Drawable.setColorFilter()不工作在Android 2.1 [英] Drawable.setColorFilter() not working on Android 2.1
本文介绍了Drawable.setColorFilter()不工作在Android 2.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Drawable d = new BitmapDrawable(BitmapFactory.decodeResource(
getResources(), R.drawable.ic_watch));
d.setColorFilter(new LightingColorFilter(color, lightenColor));
imageView.setImageDrawable(d);
在Android 2.2(模拟器)和2.3(N1)setColorFilter()工作正常。它为什么不能在2.1的工作(在模拟器测试)?另外Android的bug?
On Android 2.2 (emulator) and 2.3 (N1) setColorFilter() works fine. Why doesn't it work on 2.1 (tested on emulator)? Another Android bug?
推荐答案
您需要让你的位图
可变的。
// make a mutable Bitmap
Bitmap immutableBitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.ic_watch);
Bitmap mutableBitmap = immutableBitmap.copy(Bitmap.Config.ARGB_8888, true);
// you have two bitmaps in memory, so clean up the mess a bit
immutableBitmap.recycle(); immutableBitmap=null;
Drawable d = new BitmapDrawable(mutableBitmap);
// mutate it
d.setColorFilter(new LightingColorFilter(color, lightenColor));
imageView.setImageDrawable(d);
您可以看到这个问题突然出现在<一个href="http://stackoverflow.com/questions/4349075/bitmapfactory-de$c$cresource-returns-a-mutable-bitmap-in-android-2-2-and-an-immut">here,了。
You can see this problem cropping up over here, too.
这篇关于Drawable.setColorFilter()不工作在Android 2.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文