Can someone please explain to me what a mutable bitmap is? What advantages/disadvantages or what limitations do mutable and immutable bitmaps have?
-
1I think mutable is editable. You can draw on top of it. Immutable is not, for example the image you put in the resources folder. But for better explanation, better wait for someone else cares to explain ;) – springrolls Mar 11 '11 at 10:08
4 Answers
It's about the same difference as with String vs StringBuilder - String is immutable so you can't change its content (well at least not without any hacks), while for StringBuilder you can change its content.
In order to convert an immutable bitmap to a mutable one, check out this post: https://stackoverflow.com/a/16314940/878126.

- 2,242
- 4
- 15
- 33

- 114,585
- 152
- 739
- 1,270
If your bitmap include mutable flag, its pixels can be change, if doesn't, pixel changings throw an error. It's the difference between them.
And here is Android: convert Immutable Bitmap into Mutable

- 1,479
- 13
- 21
Not sure if there is any performance gain for using immutable bitmaps. Often immutable is just for being thread safe (or if you are going to share the image with another process, process safe)

- 154
- 1
- 8
Tries to make a new bitmap based on the dimensions of this bitmap, setting the new bitmap's config to the one specified, and then copying this bitmap's pixels into the new bitmap. and you can set config of image.

- 21,688
- 25
- 143
- 191