Open dejandobnikar opened 5 years ago
Same problem here. I tested several compression options and the file size doesn't change on Android 10.
I got the same problem and solved it.
Use!!! implementation 'com.github.yalantis: ucrop: 2.2.4-native'
Here is a detailed description:
implementation 'com.github.yalantis: ucrop: 2.2.4' :::: lightweight general solution
implementation 'com.github.yalantis: ucrop: 2.2.4-native' ::: get power of the native code to preserve image quality (+ about 1.5 MB to an apk size)
for getting smaller size output file:
String filePath = file.getPath(); Bitmap bitmap = BitmapFactory.decodeFile(filePath); Bitmap resized = Bitmap.createScaledBitmap(bitmap,(int)(bitmap.getWidth()0.4), (int)(bitmap.getHeight()0.4), true); new fileFromBitmap(resized, getActivity()).execute();
public class fileFromBitmap extends AsyncTask<Void, Integer, String> {
Context context;
Bitmap bitmap;
public fileFromBitmap(Bitmap bitmap, Context context) {
this.bitmap = bitmap;
this.context= context;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(Void... params) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
fileCom = new File(Environment.getExternalStorageDirectory() + File.separator + "temporary_file.jpg");
try {
FileOutputStream fo = new FileOutputStream(fileCom);
fo.write(bytes.toByteArray());
fo.flush();
fo.close();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
//"fileCom" is final result
}
}
I have the same problem on Android 10.
implementation 'com.github.yalantis: ucrop: 2.2.4-native' ::: get power of the native code to preserve image quality (+ about 1.5 MB to an apk size)
this solution save my days, thank's @uijun
Hi @uijun @edinofricaniago, Even though changed from lightweight to native, I'm getting same quality issue. If possible, Please share snippet here.
Thanks :)
Do you want to request a feature or report a bug? bug
What is the current behavior? Pixel 3 running Android Q Beta 5: Panorama Image with dimensions approx 6000x5000px and file size 7.6MB is cropped to 1920x1920px, file size is 7MB Pixel running Android P: Same image cropped to 1920x1920px, resulting file size is 1.1MB. The same image is selected from Google Photos via Intent.
What is the expected behavior? Smaller file size is expected on both devices & Android versions.
Which versions of uCrop, and which Android API versions are affected by this issue? Did this work in previous versions of uCrop? 2.2.2
This may be Android Q issue, but I think the issue should be tracked anyway. Will add a comment if I have any more info.