【发布时间】:2016-11-07 10:56:30
【问题描述】:
我尝试从图库中调整位图的大小。我写了一些代码,我只能调整位图的静态宽度和高度。这是源代码
public Bitmap getResizedBitmap(Bitmap bm, int newWidth) {
float aspectRatio = (float)bm.getWidth() / (float) bm.getHeight();
int height = Math.round(newWidth / aspectRatio); //based on width it gives height
Matrix matrix = new Matrix();
matrix.postScale(newWidth, height);
Bitmap resizedBitmap = Bitmap.createBitmap(
bm, 0, 0, newWidth, height, matrix, false);
return resizedBitmap;
}
但我想调整位图的大小,例如宽度 800 像素和自动高度。是否有可能在 android 中解决这个问题? 谢谢
【问题讨论】:
-
refer this link 我也从这个链接得到了同样问题的解决方案
标签: android bitmap android-imageview android-bitmap