Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It looks like you only want to display a 160x160 bitmap, but on this line you are reading in the whole bitmap and then later scaling it down.</p> <pre><code>imageSelected = android.provider.MediaStore.Images.Media(cr, selectedImage); </code></pre> <p>You can avoid ever loading the whole bitmap into memory by using <a href="http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html#inJustDecodeBounds" rel="nofollow">inJustDecodeBounds</a>, and then you can scale it using <a href="http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html#inSampleSize" rel="nofollow">inSampleSize</a>.</p> <p>Here is some example code from the Android series on <a href="http://developer.android.com/training/displaying-bitmaps/load-bitmap.html" rel="nofollow">Loading Large Bitmaps Efficiently</a></p> <pre><code>public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) { // Raw height and width of image final int height = options.outHeight; final int width = options.outWidth; int inSampleSize = 1; if (height &gt; reqHeight || width &gt; reqWidth) { if (width &gt; height) { inSampleSize = Math.round((float)height / (float)reqHeight); } else { inSampleSize = Math.round((float)width / (float)reqWidth); } } return inSampleSize; } public static Bitmap decodeSampledBitmapFromUri(Uri uri, int reqWidth, int reqHeight) { // First decode with inJustDecodeBounds=true to check dimensions final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, options); } </code></pre> <p>Then to get your 160x160 image you would just do:</p> <pre><code>ivImageLoad.setImageBitmap(decodeSampledBitmapFromUri(selectedImage, 100, 100)); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload