【问题标题】:How to set masked image to size of bitmap to be masked?如何将蒙版图像设置为要蒙版的位图大小?
【发布时间】: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


    【解决方案1】:

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

    public static Bitmap createScaledBitmap (Bitmap src, int dstWidth, int dstHeight, boolean filter)

    文档链接: http://developer.android.com/reference/android/graphics/Bitmap.html#createScaledBitmap(android.graphics.Bitmap, int, int, boolean)

    【讨论】:

      猜你喜欢
      • 2012-12-16
      • 2020-09-23
      • 2020-05-13
      • 1970-01-01
      • 2018-07-29
      • 1970-01-01
      • 1970-01-01
      • 2014-05-14
      • 1970-01-01
      相关资源
      最近更新 更多