22

A:

 Bitmap immutableBmp= BitmapFactory.decodeResource(getApplicationContext().getResources(),R.drawable.sample);
 mutableBitmap=immutableBmp.copy(Bitmap.Config.ARGB_8888, true);

B:

Bitmap immutableBmp= BitmapFactory.decodeFile(filePath);
mutableBitmap=immutableBmp.copy(Bitmap.Config.ARGB_8888, true);

C:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inMutable=true;
myBitmap=BitmapFactory.decodeFile(filePath,options);

A works but B and C don't. I am trying to convert an immutable bitmap to mutable. It works on resource images but not file images. What's the problem?

Alex
  • 881
  • 2
  • 10
  • 24
  • Unlike forum sites, we don't use "Thanks", or "Any help appreciated", or signatures on [so]. See "[Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts). BTW, it's "Thanks in advance", not "Thanks in advanced". – John Saunders May 24 '15 at 22:51
  • Doesn't work, hm? What does this mean exactly? A wild guess....your path is wrong. – ElDuderino May 24 '15 at 23:18
  • Sorry @JohnSaunders, i thought i should be polite haha, thanks for informing – Alex May 25 '15 at 06:00
  • @ElDuderino The image from file does show up in the imageview just tat i am not able to draw on the image anymore. What's wrong? – Alex May 25 '15 at 06:02
  • @Alex: if you read the link, you'll find that politeness is nice when you're having a conversation. But we're not having a conversation here. Just Q&A. – John Saunders May 25 '15 at 06:13

2 Answers2

13

Found this:

Bitmap bmp_Copy = bmp_Base.copy(Bitmap.Config.ARGB_8888,true);
Florian Erwig
  • 131
  • 1
  • 4
  • 6
    It's good practice on Stack Overflow to add an explanation as to why your solution should work. For more information read [How To Answer](//stackoverflow.com/help/how-to-answer). – Samuel Liew Apr 17 '18 at 12:53
2

I have found the problem! All of the 3 methods above are working, there was a problem with the resolution of my image, so I thought the code didn't work and it was not mutable but I was wrong. Here is another solution to change immutable image to mutable.

BitmapFactory.decodeResource returns a mutable Bitmap in Android 2.2 and an immutable Bitmap in Android 1.6

Alex
  • 881
  • 2
  • 10
  • 24