Ananas icon indicating copy to clipboard operation
Ananas copied to clipboard

App crash if big size image is provided

Open farrakhj opened this issue 3 years ago • 4 comments

In the below method from EditImageActivity app crashes if large image(provided 14MB image) is provided. private Single<Bitmap> loadImage(String filePath) { return Single.fromCallable(() -> BitmapUtils.getSampledBitmap(filePath, imageWidth, imageHeight)); }

public static Bitmap getSampledBitmap(String filePath, int reqWidth, int reqHeight) throws FileNotFoundException { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); options.inPreferredConfig = Bitmap.Config.RGB_565; options.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filePath, options); }

If image size is small or big getSampleBitmap method always calculate sample size as 1.

If anyone faced this issue please post against this issue.

farrakhj avatar Oct 29 '21 13:10 farrakhj

Above code create BitmapFactory.Options with options instance. options instance is never loaded with filePath image data. So this always return sampleSize 1 for every image. The correct code should be as below. Line added in highlighted:

public static Bitmap getSampledBitmap(String filePath, int reqWidth, int reqHeight) throws FileNotFoundException { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;

BitmapFactory.decodeFile(filePath, options);

options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); options.inPreferredConfig = Bitmap.Config.RGB_565; options.inJustDecodeBounds = false;` return BitmapFactory.decodeFile(filePath, options); }

farrakhj avatar Nov 01 '21 05:11 farrakhj

@iamutkarshtiwari

farrakhj avatar Nov 01 '21 13:11 farrakhj

Hi @farrakhj, thank you for reporting this issue! Oh, you already found the cause. Would you like to make a PR for it?

iamutkarshtiwari avatar Mar 12 '22 05:03 iamutkarshtiwari

Sure i would like to create PR for it. Can you please guide the steps as i am new at GitHub?

farrakhj avatar Apr 01 '22 12:04 farrakhj