Convert immutable Bitmap file to mutable Bitmap

拟墨画扇 提交于 2021-01-19 14:19:16

问题


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?


回答1:


Found this:

Bitmap bmp_Copy = bmp_Base.copy(Bitmap.Config.ARGB_8888,true);



回答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



来源:https://stackoverflow.com/questions/30425789/convert-immutable-bitmap-file-to-mutable-bitmap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!