将不可变位图文件转换为可变位图 [英] Convert immutable Bitmap file to mutable Bitmap
本文介绍了将不可变位图文件转换为可变位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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有效,而B和C无效.我试图将不可变的位图转换为可变的.它适用于资源映像,但不适用于文件映像.有什么问题?
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?
推荐答案
我发现了问题!上面的所有3种方法都可以使用,但是我的图像分辨率存在问题,所以我认为代码无法正常工作,并且不可变,但是我错了.这是将不可变图像更改为可变的另一种解决方案.
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在Android 2.2中返回可变的位图,在Android 1.6中返回不可变的位图
这篇关于将不可变位图文件转换为可变位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文