Image Scaling Android
<p>I'm showing images from gallery to Imageview.</p>

<p>I'm using below code</p>

<pre><code> Bitmap background = Bitmap.createBitmap((int) width, (int) height, Bitmap.Config.ARGB_8888);
                float originalWidth = bMap.getWidth(), originalHeight = bMap.getHeight();
                Canvas canvas = new Canvas(background);
                float scale = width/originalWidth;
                float xTranslation = 0.0f, yTranslation = (height - originalHeight * scale)/2.0f;
                Matrix transformation = new Matrix();
                transformation.postTranslate(xTranslation, yTranslation);
                transformation.preScale(scale, scale);
                Paint paint = new Paint();
                paint.setFilterBitmap(true);
                canvas.drawBitmap(bMap, transformation, paint);
                imageView1.setImageBitmap(background);
</code></pre>

<p>Case 1: working.</p>

<p><a href="http://i1027.photobucket.com/albums/y332/manishparab31/IMG_20160213_222738243%201_zpss3iosyg3.jpg" rel="nofollow">Original Image</a></p>

<p><a href="http://i1027.photobucket.com/albums/y332/manishparab31/Screenshot_2016-02-15-12-36-58_zpsgshwcdkv.png" rel="nofollow">Output of above code.</a></p>

<p>Case 2: not working</p>

<p><a href="http://i1027.photobucket.com/albums/y332/manishparab31/IMG_20160213_222638497_zpsdbkyjivx.jpg" rel="nofollow">Original Image.</a></p>

<p><a href="http://i1027.photobucket.com/albums/y332/manishparab31/Screenshot_2016-02-15-12-37-10_zpsne95areh.png" rel="nofollow">Output of above code.</a></p>

<p>in case 2 why image is not getting scaled properly, to fill the imageview?
Please let me know where I'm going wrong.</p>