Skip to content
This repository has been archived by the owner on Jan 7, 2023. It is now read-only.

Fix certain JPEG files are failed to be decoded with BitmapRegionDecoder #219

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,10 @@ private Bitmap decodeRegionCrop(Rect rect, int outWidth, int outHeight) {
Bitmap croppedImage = null;
try {
is = getContentResolver().openInputStream(sourceUri);
BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(is, false);
final int width = decoder.getWidth();
final int height = decoder.getHeight();
croppedImage = BitmapFactory.decodeStream(is);
final int width = croppedImage.getWidth();
final int height = croppedImage.getHeight();


if (exifRotation != 0) {
// Adjust crop area to account for image rotation
Expand All @@ -343,7 +344,8 @@ private Bitmap decodeRegionCrop(Rect rect, int outWidth, int outHeight) {
}

try {
croppedImage = decoder.decodeRegion(rect, new BitmapFactory.Options());
croppedImage = Bitmap.createBitmap(croppedImage, rect.left, rect.top, rect.width(), rect.height());

if (croppedImage != null && (rect.width() > outWidth || rect.height() > outHeight)) {
Matrix matrix = new Matrix();
matrix.postScale((float) outWidth / rect.width(), (float) outHeight / rect.height());
Expand Down