@Override protected File doInBackground(ImageFile... params) { Log.i(TAG, "------------------ start compress file ------------------"); ImageFile srcFileInfo = params[0]; Bitmap.CompressFormat format = mCompressFormat; if (format == null) { format = CompressFormatUtils.parseFormat(srcFileInfo.mSrcFilePath); } Log.i(TAG, "use compress format:" + format.name()); File outputFile = CommonUtils.generateExternalImageCacheFile(mContext, CompressFormatUtils.getExt(format)); File srcFile = new File(srcFileInfo.mSrcFilePath); boolean isCompress = compressImageFile( srcFileInfo.mSrcFilePath, outputFile.getPath(), mMaxWidth, mMaxHeight, mQuality, format); if (!isCompress) { // 没有压缩,直接copy CommonUtils.copy(srcFile, outputFile); } if (srcFileInfo.mDeleteSrc) { srcFile.delete(); } return outputFile; }
@Override protected List<String> doInBackground(ImageFile... params) { Log.i(TAG, "------------------ start compress file ------------------"); List<String> outs = new ArrayList<>(params.length); for (ImageFile srcFileInfo : params) { Bitmap.CompressFormat format = mCompressFormat; if (format == null) { format = CompressFormatUtils.parseFormat(srcFileInfo.mSrcFilePath); } File outputFile = CommonUtils.generateExternalImageCacheFile( mContext, CompressFormatUtils.getExt(format)); File srcFile = new File(srcFileInfo.mSrcFilePath); boolean isCompress = compressImageFile( srcFileInfo.mSrcFilePath, outputFile.getPath(), mMaxWidth, mMaxHeight, mQuality, format); if (!isCompress) { // 没有压缩,直接copy CommonUtils.copy(srcFile, outputFile); } if (srcFileInfo.mDeleteSrc) { //noinspection ResultOfMethodCallIgnored srcFile.delete(); } outs.add(outputFile.getPath()); } return outs; }