public static Bitmap zoomImage(Bitmap bgimage, double newWidth, double newHeight) {
// 获取这个图片的宽和高
float width = bgimage.getWidth();
float height = bgimage.getHeight();
// 创建操作图片用的matrix对象
Matrix matrix = new Matrix();
// 计算宽高缩放率
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// 缩放图片动作
matrix.postScale(scaleWidth, scaleHeight);
Bitmap bitmap = Bitmap.createBitmap(bgimage, 0, 0, (int) width,
(int) height, matrix, true);
return bitmap;
}android压缩图片到指定尺寸
最新推荐文章于 2023-10-20 09:19:30 发布
本文介绍了一种使用 Android 的 Matrix 类实现的图片缩放方法。该方法通过计算目标宽度和高度与原始图片尺寸的比例来调整图片大小,适用于需要改变图片尺寸的应用场景。
1134

被折叠的 条评论
为什么被折叠?



