如何将蒙版图像设置为要蒙版的位图大小?

How to set masked image to size of bitmap to be masked?

我正在创建一个拼图游戏,我正在使用遮罩来创建拼图游戏。通过实验,我了解到如果掩码位图与要被掩码的位图大小不同,结果 'can' 会偏离预期形状。我 运行 遇到的冲突是,在尝试将蒙版图像的大小调整为等于拼图的大小时,因为拼图块的大小是随机的,具体取决于块的数量和难度级别等,蒙版图像变形并变成正方形或长方形。

我正在使用矩阵函数像这样调整我的掩码位图

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不再是拼图形状,是正方形或者长方形。所以即使我用那个图像遮罩,它也只会创建正方形。另一种方法是将拼图块调整为一组蒙面图像,但我想知道是否有办法调整蒙面位图的大小(保留拼图形状)?提前致谢!

尝试使用此功能,看看它是否有效:

public static Bitmap createScaledBitmap (Bitmap src, int dstWidth, int dstHeight, 布尔过滤器)

Link 到文档: http://developer.android.com/reference/android/graphics/Bitmap.html#createScaledBitmap(android.graphics.Bitmap, 整数, 整数, 布尔值)