Yalantis / uCrop

Image Cropping Library for Android
https://yalantis.com/blog/introducing-ucrop-our-own-image-cropping-library-for-android/
11.87k stars 2.16k forks source link

Android Q: File size #546

Open dejandobnikar opened 5 years ago

dejandobnikar commented 5 years ago

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.

HenriqueMonte commented 4 years ago

Same problem here. I tested several compression options and the file size doesn't change on Android 10.

uijun commented 4 years ago

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)

mnaeimabadi commented 4 years ago

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

    }
}
julaee commented 4 years ago

I have the same problem on Android 10.

edinofricaniago commented 4 years ago

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

RagulSAP commented 4 years ago

Hi @uijun @edinofricaniago, Even though changed from lightweight to native, I'm getting same quality issue. If possible, Please share snippet here.

Thanks :)