How do I use a matrix to resize a bitmap in SurfaceView?

元气小坏坏 提交于 2019-12-13 20:35:10

问题


I found this bit of code on a similar question, but I can't figure out how to use it.

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;
}

I'm also confused as to where to place this. With my initial variables? Inside the constructor, or runnable? If the bitmap I wanted to change the size of is called Background, how do I add that to this method?

Thanks in advance.

来源:https://stackoverflow.com/questions/24945950/how-do-i-use-a-matrix-to-resize-a-bitmap-in-surfaceview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!