20
20
import android .content .Intent ;
21
21
import android .graphics .Bitmap ;
22
22
import android .graphics .BitmapFactory ;
23
- import android .graphics .BitmapRegionDecoder ;
24
- import android .graphics .Canvas ;
25
23
import android .graphics .Matrix ;
26
- import android .graphics .Paint ;
27
24
import android .graphics .Rect ;
28
25
import android .graphics .RectF ;
29
26
import android .net .Uri ;
@@ -337,9 +334,9 @@ private Bitmap decodeRegionCrop(Rect rect, int outWidth, int outHeight) {
337
334
Bitmap croppedImage = null ;
338
335
try {
339
336
is = getContentResolver ().openInputStream (sourceUri );
340
- BitmapRegionDecoder decoder = BitmapRegionDecoder . newInstance (is , false );
341
- final int width = decoder .getWidth ();
342
- final int height = decoder .getHeight ();
337
+ croppedImage = BitmapFactory . decodeStream (is );
338
+ final int width = croppedImage .getWidth ();
339
+ final int height = croppedImage .getHeight ();
343
340
344
341
if (exifRotation != 0 ) {
345
342
// Adjust crop area to account for image rotation
@@ -359,7 +356,7 @@ private Bitmap decodeRegionCrop(Rect rect, int outWidth, int outHeight) {
359
356
if ((rect .width () > outWidth || rect .height () > outHeight )) {
360
357
switch (scaleMethod ) {
361
358
case EXACT :
362
- croppedImage = decoder . decodeRegion ( rect , options );
359
+ croppedImage = Bitmap . createBitmap ( croppedImage , rect . left , rect . top , rect . width (), rect . height () );
363
360
Matrix matrix = new Matrix ();
364
361
matrix .postScale ((float ) outWidth / rect .width (), (float ) outHeight / rect .height ());
365
362
croppedImage = Bitmap .createBitmap (croppedImage , 0 , 0 , croppedImage .getWidth (), croppedImage .getHeight (), matrix , true );
@@ -373,11 +370,11 @@ private Bitmap decodeRegionCrop(Rect rect, int outWidth, int outHeight) {
373
370
h = rect .height () / inSampleSize ;
374
371
} while (w > outWidth && h > outHeight );
375
372
options .inSampleSize = inSampleSize ;
376
- croppedImage = decoder . decodeRegion ( rect , options );
373
+ croppedImage = Bitmap . createBitmap ( croppedImage , rect . left , rect . top , w , h );
377
374
break ;
378
375
}
379
376
} else {
380
- croppedImage = decoder . decodeRegion ( rect , options );
377
+ croppedImage = Bitmap . createBitmap ( croppedImage , rect . left , rect . top , rect . width (), rect . height () );
381
378
}
382
379
} catch (IllegalArgumentException e ) {
383
380
// Rethrow with some extra information
0 commit comments