Decode image from uri using given "inSampleSize", but if failed due to out-of-memory then raise the inSampleSize until success.
(ContentResolver resolver, Uri uri, BitmapFactory.Options options)
| 353 | * raise the inSampleSize until success. |
| 354 | */ |
| 355 | private static Bitmap decodeImage(ContentResolver resolver, Uri uri, BitmapFactory.Options options) |
| 356 | throws FileNotFoundException |
| 357 | { |
| 358 | do |
| 359 | { |
| 360 | InputStream stream = null; |
| 361 | try |
| 362 | { |
| 363 | stream = resolver.openInputStream(uri); |
| 364 | return BitmapFactory.decodeStream(stream, EMPTY_RECT, options); |
| 365 | } |
| 366 | catch(OutOfMemoryError e) |
| 367 | { |
| 368 | options.inSampleSize *= 2; |
| 369 | } |
| 370 | finally |
| 371 | { |
| 372 | closeSafe(stream); |
| 373 | } |
| 374 | } while(options.inSampleSize <= 512); |
| 375 | throw new RuntimeException("Failed to decode image: " + uri); |
| 376 | } |
| 377 | |
| 378 | /** |
| 379 | * Decode specific rectangle bitmap from stream using sampling to get bitmap with the requested |
no test coverage detected