android 调整位图自动高度
android resize bitmap auto height
我尝试调整位图的大小 gallery.I 写了一些代码,我只能调整位图的静态宽度并且 height.this 是来源
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;
}
但我想调整位图的大小,例如宽度 800px 和自动 height.is 是否可以在 android 中解决这个问题?
谢谢
float aspectRatio = (float)Image.getWidth() / (float) Image.getHeight();
int width = 200; //your width
int height = Math.round(width / aspectRatio); //based on width it gives height
public Bitmap getResizedBitmap(Bitmap bm, int newWidth, int newHeight) {
int width = bm.getWidth();
int height = bm.getHeight();
Bitmap resizedBitmap;
try {
resizedBitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight());
}catch (Exception e){
e.printStackTrace();
boolean_image = true;
return "";
}
return resizedBitmap;
}
我尝试调整位图的大小 gallery.I 写了一些代码,我只能调整位图的静态宽度并且 height.this 是来源
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;
}
但我想调整位图的大小,例如宽度 800px 和自动 height.is 是否可以在 android 中解决这个问题? 谢谢
float aspectRatio = (float)Image.getWidth() / (float) Image.getHeight();
int width = 200; //your width
int height = Math.round(width / aspectRatio); //based on width it gives height
public Bitmap getResizedBitmap(Bitmap bm, int newWidth, int newHeight) {
int width = bm.getWidth();
int height = bm.getHeight();
Bitmap resizedBitmap;
try {
resizedBitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight());
}catch (Exception e){
e.printStackTrace();
boolean_image = true;
return "";
}
return resizedBitmap;
}