开发者

Android BitmapFactory.decodeResource multiple times

开发者 https://www.devze.com 2023-01-21 15:58 出处:网络
So开发者_JS百科me background. I currently have a class that is instantiated multiple times and inside the class resides a Bitmap member variable that is set using BitmapFactory.decodeResource on insta

So开发者_JS百科me background. I currently have a class that is instantiated multiple times and inside the class resides a Bitmap member variable that is set using BitmapFactory.decodeResource on instantiation. At any time I may need to apply a matrix to the bitmap and it's currently done via:

public void applyMatrix(Matrix matrix) {
    mBitmap = Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), matrix, true);
}

I am making the assumption that every time I instantiate this class it must load the Bitmap into memory (again). Is that in fact the case? I was also considering pre-loading all bitmaps into an array and referencing the index instead, but I would still run into a problem when I need to transform the Bitmap - I would have to create a new Bitmap from the one in memory. Is there a better way to do this?


You should always transform the canvas and not the bitmap. This alleviates all issues I was concerned about.

0

精彩评论

暂无评论...
验证码 换一张
取 消