Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Hope following solution helps. You can make your imageView of fixed size and pass that imageView's width and height to <code>calculateInSampleSize</code> method. Based on image size, it will decide whether to down sample the image or not.</p> <pre><code>public Bitmap getBitmap(Context context, final String imagePath) { AssetManager assetManager = context.getAssets(); InputStream inputStream = null; Bitmap bitmap = null; try { inputStream = assetManager.open(imagePath); BitmapFactory.Options options = new BitmapFactory.Options(); options.inScaled = true; options.inJustDecodeBounds = true; // First decode with inJustDecodeBounds=true to check dimensions bitmap = BitmapFactory.decodeStream(inputStream); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, requiredWidth, requiredHeight); options.inJustDecodeBounds = false; bitmap = BitmapFactory.decodeStream(inputStream); } catch(Exception exception) { exception.printStackTrace(); bitmap = null; } return bitmap; } public int calculateInSampleSize(BitmapFactory.Options options, final int requiredWidth, final int requiredHeight) { // Raw height and width of image final int height = options.outHeight; final int width = options.outWidth; int inSampleSize = 1; if(height &gt; requiredHeight || width &gt; requiredWidth) { if(width &gt; height) { inSampleSize = Math.round((float)height / (float)requiredHeight); } else { inSampleSize = Math.round((float)width / (float)requiredWidth); } } return inSampleSize; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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