【发布时间】:2015-02-18 02:13:34
【问题描述】:
我正在创建一个拼图游戏,我正在使用面具来创建拼图游戏。通过实验,我了解到如果掩码位图与要掩码的位图大小不同,则结果“可能”与预期的形状有所不同。我遇到的冲突是,在尝试将蒙版图像调整为等于拼图的大小时,因为拼图块的大小是随机的,具体取决于块数和难度级别等,蒙版图像失去了形状和变成正方形或长方形。
我正在使用矩阵函数来调整我的掩码位图的大小
public static Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth = (float) newWidth / width;
float scaleHeight = (float) newHeight / height;
// create a matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bitmap
matrix.postScale(scaleWidth, scaleHeight);
// recreate the bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
return resizedBitmap;
}
returnedBitmap 不再是拼图形状,它是正方形或矩形。因此,即使我使用该图像进行遮罩,它也只会创建正方形。另一种方法是将拼图块调整为一组蒙版图像,但我想知道是否有办法调整蒙版位图的大小(保留拼图形状)?提前致谢!
【问题讨论】:
标签: android bitmap resize-image