使用ExecutorService压缩图像文件列表

问题描述

我正在尝试压缩图像文件列表,并在压缩后将其存储在缓存目录中。这里的问题是某些图像文件未正确压缩。它提供了一些半压缩的图像。请帮助我解决此问题。

请检查下面的半压缩图像

https://i.stack.imgur.com/s3tDh.png

这是我的代码

            val latch = CountDownLatch(uriList.size)
            val executorService: ExecutorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())


            val callables: MutableList<Callable<String>> = java.util.ArrayList()
            for (i in 0 until uriList.size) {
                val uri: Uri = uriList[i]

                callables.add(Callable<String> {
                    publishProgress(i.toString())
                    val imageCompresser = ImageCompresser(App.context)
                    val tempString1 = imageCompresser.compressImage(uri.path!!)
                    latch.countDown();
                    tempString1
                })
            }

            var resultList: List<Future<String>>? = null;
            try {
                resultList = executorService.invokeAll(callables);
            } catch (e: InterruptedException) {
                e.printstacktrace();
            }

            try {
                latch.await();
            } catch (E: InterruptedException) {
                // handle
            }
            try {
                for (future in resultList!!) {
                    mImagePathsList.add(future.get().toString())
                }
            } catch (ce: CancellationException) {
                ce.printstacktrace();
            } catch (ee: ExecutionException) {
                ee.printstacktrace();
            } catch (ie: InterruptedException) {
                Thread.currentThread().interrupt();
            }


            executorService.shutdown()
            while (!executorService.isTerminated) {
              
            }
            executorService.shutdown()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)