17

The Bitmap class has a method copy() with the signature below:

public Bitmap copy(Bitmap.Config config, boolean isMutable)

Is there a performance difference between a mutable and an immutable Bitmap?

Adam Stelmaszczyk
  • 19,665
  • 4
  • 70
  • 110
  • 2
    I would be surprised if there's a significant difference. – Hot Licks Mar 11 '13 at 20:20
  • I would be surprised too, but other than code hardening I can't imagine a functional reason to choose one over the other. That said, because it hardens the code, it would generally be better to make it immutable. Any performance gains you get would be gained because you have the knowledge the image will never change. – DeeV Mar 11 '13 at 20:29
  • 4
    The reason for immutable bitmaps is that they save you resources (when you copy an immutable bitmap to another immutable one, the C pointer still points to the same location so there's no need for a real copy). Everything else, however, stays the same so to your question, no there is no performance change, but if you care about system resources, you should use immutable bitmaps whenever possible. I remember Romain Guy writing a post about it but I can't find it. – EyalBellisha Mar 12 '13 at 09:10
  • 3
    @androidcompile Bitmap.copy() will copy the content of the Bitmap, they do not point to the same storage (the Bitmap you're copying from might be mutable.) What you are describing is what we do for Drawables. – Romain Guy Mar 12 '13 at 20:39
  • 11
    To answer the original question: no, there is no performance difference. There are some optimizations we could implement for mutable bitmaps though. Hopefully in a future release :) – Romain Guy Mar 12 '13 at 20:41
  • @RomainGuy And that was an answer not a comment, so please use Stackoverflow as it is meant to be used so us necromancers don't waste our time :D – Warpzit Mar 18 '13 at 09:09

3 Answers3

8

Romain Guy answered in the comments:

To answer the original question: no, there is no performance difference. There are some optimizations we could implement for mutable bitmaps though. Hopefully in a future release :)

Community
  • 1
  • 1
Adam Stelmaszczyk
  • 19,665
  • 4
  • 70
  • 110
0

There is no performance difference. This will not affect the performance of your app. If you want to perform any opration like rotation etc then i think the bitmap should be mutable...

Manmohan Soni
  • 6,472
  • 2
  • 23
  • 29
-3

On Application level, there is always a difference between immutable & mutable Bitmap resources.

You always get an immutable Bitmap from the resources. you need to convert them into mutable bitmap as per necessiti.

Bitmap Bitmap = BitmapFactory.decodeResource(....); Bitmap mutableBitmap = immutableBitmap.copy(Bitmap.Config.ARGB_8888, true);

So probably there must be a performance issue in this reference.

Suresh Sharma
  • 1,826
  • 22
  • 41
  • 3
    Two downvotes and no comments? Really? As a user, this gives me no idea if the answer is factually wrong, just confusing to the voter, or some third option. – Patrick M Sep 25 '13 at 11:58