Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrakal committed Mar 31, 2017
1 parent c83cbf1 commit a135f37
Showing 1 changed file with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapRegionDecoder;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.net.Uri;
Expand Down Expand Up @@ -337,9 +334,9 @@ 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 @@ -359,7 +356,7 @@ private Bitmap decodeRegionCrop(Rect rect, int outWidth, int outHeight) {
if ((rect.width() > outWidth || rect.height() > outHeight)) {
switch (scaleMethod) {
case EXACT:
croppedImage = decoder.decodeRegion(rect, options);
croppedImage = Bitmap.createBitmap(croppedImage, rect.left, rect.top, rect.width(), rect.height());
Matrix matrix = new Matrix();
matrix.postScale((float) outWidth / rect.width(), (float) outHeight / rect.height());
croppedImage = Bitmap.createBitmap(croppedImage, 0, 0, croppedImage.getWidth(), croppedImage.getHeight(), matrix, true);
Expand All @@ -373,11 +370,11 @@ private Bitmap decodeRegionCrop(Rect rect, int outWidth, int outHeight) {
h = rect.height() / inSampleSize;
} while(w > outWidth && h > outHeight);
options.inSampleSize = inSampleSize;
croppedImage = decoder.decodeRegion(rect, options);
croppedImage = Bitmap.createBitmap(croppedImage, rect.left, rect.top, w, h);
break;
}
} else {
croppedImage = decoder.decodeRegion(rect, options);
croppedImage = Bitmap.createBitmap(croppedImage, rect.left, rect.top, rect.width(), rect.height());
}
} catch (IllegalArgumentException e) {
// Rethrow with some extra information
Expand Down

0 comments on commit a135f37

Please sign in to comment.