开发者

Create a subset of Bitmap without make a copy

开发者 https://www.devze.com 2023-02-04 12:24 出处:网络
I have this problem, when I try to make a new bitmap for another one, like this: first_data = Bitmap.createBitmap(data, 0, 0, data.getWidth() / 2,data.getHeight());

I have this problem, when I try to make a new bitmap for another one, like this:

first_data = Bitmap.createBitmap(data, 0, 0, data.getWidth() / 2,data.getHeight()); 
second_data =  Bitmap.createBitmap(data, data.getWidth() / 2, 0, data.getWidth() / 2, 
data.getHeight() ); 

I meet an OutOfMemoryException...

If i use only the original full image 开发者_如何学编程I don't meet this issues, I think that Bitmap.createBitmap() make a copy of the original first image. There are a way to specify that I DON'T WANT make a copy of that? Thanks a lot!


Unfortunately, it seems like:

  • the BitMap.createBitmap() signature you are using is the correct way to 'subset' a bitmap
  • that same method's contract allows it to either return a view over the same bytes or to copy them

If your original bitmap were immutable (isMutable() == false), that would give some encouragement for it to return an object based on the same byte array, rather than copy the same.

To get an immutable bitmap, you could try createBitmap(Bitmap) and discard all references to the original (and/or use recycle())?

0

精彩评论

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