如何在SurfaceView中使用矩阵调整位图大小?

时间:2014-07-25 00:00:35

标签: android bitmap surfaceview

我在similar question上找到了这段代码,但我无法弄清楚如何使用它。

Resizing a Bitmap:

public 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 bit map
    matrix.postScale(scaleWidth, scaleHeight);
    // recreate the new Bitmap
    Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
    return resizedBitmap;
}

我也很困惑在哪里放置它。用我的初始变量?在构造函数内部,还是runnable?如果我想要更改大小的位图称为Background,我该如何将其添加到此方法?

提前致谢。

0 个答案:

没有答案