private static Bitmap createScaledBitmap(Bitmap bm, int newWidth, int newHeight) {
int w = bm.getWidth(); // 得到图片的宽,高
int h = bm.getHeight();
int retX;
int retY;
double wh = (double) w / (double) h;
double nwh = (double) newWidth / (double) newHeight;
if (wh > nwh) {
retX = h * newWidth / newHeight;
retY = h;
} else {
retX = w;
retY = w * newHeight / newWidth;
}
int startX = w > retX ? (w - retX) / 2 : 0;//基于原图,取正方形左上角x坐标
int startY = h > retY ? (h - retY) / 2 : 0;
Bitmap bit = Bitmap.createBitmap(bm, startX, startY, retX, retY, null, false);
bm.recycle();
return bit;
}
来源网络,原作者未知,侵权请告知备注原作者姓名或删除。
private static Bitmap createScaledBitmap(Bitmap bm, int newWidth, int newHeight) {
int w = bm.getWidth(); // 得到图片的宽,高
int h = bm.getHeight();
int retX;
int retY;
double wh = (double) w / (double) h;
double nwh = (double) newWidth / (double) newHeight;
if (wh > nwh) {
retX = h * newWidth / newHeight;
retY = h;
} else {
retX = w;
retY = w * newHeight / newWidth;
}
int startX = w > retX ? (w - retX) / 2 : 0;//基于原图,取正方形左上角x坐标
int startY = h > retY ? (h - retY) / 2 : 0;
Bitmap bit = Bitmap.createBitmap(bm, startX, startY, retX, retY, null, false);
bm.recycle();
return bit;
}
来源网络,原作者未知,侵权请告知备注原作者姓名或删除。
private static Bitmap createScaledBitmap(Bitmap bm, int newWidth, int newHeight) {
int w = bm.getWidth(); // 得到图片的宽,高
int h = bm.getHeight();
int retX;
int retY;
double wh = (double) w / (double) h;
double nwh = (double) newWidth / (double) newHeight;
if (wh > nwh) {
retX = h * newWidth / newHeight;
retY = h;
} else {
retX = w;
retY = w * newHeight / newWidth;
}
int startX = w > retX ? (w - retX) / 2 : 0;//基于原图,取正方形左上角x坐标
int startY = h > retY ? (h - retY) / 2 : 0;
Bitmap bit = Bitmap.createBitmap(bm, startX, startY, retX, retY, null, false);
bm.recycle();
return bit;
}
来源网络,原作者未知,侵权请告知备注原作者姓名或删除。