Compressor
Compressor copied to clipboard
Usage for non-UI thread
My compress function is inside non-Ui thread. What should I do?
I did something like this. I moved this function inside asynctask.
Is this the right way and do you have any other idea? Use asynctask execute() correctly or should I use executeOnExecutor() or not use get() function?
public static class compressFile extends AsyncTask<Void, File, File> {
@Override
protected File doInBackground(Void... params) {
File thumbFile = null;
try {
thumbFile = new Compressor(MyApplication.getContext())
.setMaxWidth(width)
.setMaxHeight(height)
.setQuality(quality)
.setCompressFormat(Bitmap.CompressFormat.JPEG)
.compressToFile(new File(path), " " + System.currentTimeMillis());
} catch (Exception e) {
Mylog.printStackTrace(TAG + " error", e);
}
return thumbFile;
}
}
compress image usage in non-UI thread:
File compressedBigFile = new compressFile().execute().get();