Android Resize Bitmap Keeping Aspect Ratio
I have a custom view (1066 x 738), and I am passing a bitmap image (720x343). I want to scale the bitmap to fit in the custom view without exceeding the bound of the parent. I wan
Solution 1:
You should try using a transformation matrix built for ScaleToFit.CENTER
. For example:
Matrix m = new Matrix();
m.setRectToRect(new RectF(0, 0, b.getWidth(), b.getHeight()), new RectF(0, 0, reqWidth, reqHeight), Matrix.ScaleToFit.CENTER);
return Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), m, true);
Post a Comment for "Android Resize Bitmap Keeping Aspect Ratio"