1

I am compressing an image which is taken from the Gallery using a method which works most of the times. Here's the code :

public static Uri compressImage(Context context, Uri inputUri){
    String realPath = UtilityUriHelper.getPath(context, inputUri);
    File realFile = new File(realPath);

    File compressedImg = new Compressor.Builder(context)
            .setMaxHeight(1920)
            .setMaxWidth(1920)
            .setQuality(70)
            .setCompressFormat(Bitmap.CompressFormat.JPEG)
            .build()
            .compressToFile(realFile);

    return Uri.fromFile(compressedImg);
}

So the error happen sometimes when I pick the same image over and over again. And the error is width and height must be > 0

I don't really understand why, sometimes it happens sometimes it doesn't.

If I have to do the checking on width and height, how to get the width and height before it's sent into Compressor.Builder()? Or I should do something else here?

Kevin Murvie
  • 2,592
  • 1
  • 25
  • 43

0 Answers0