2011-03-31 64 views
5
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错误?Drawable.setColorFilter()不能在Android 2.1上工作

回答

9

你需要让你的Bitmap可变。

// 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); 

你可以看到这个问题出现在here以上。

+0

谢谢,我会尝试的!如果它不起作用,我会让你知道。 – fhucho 2011-04-12 14:56:42

相关问题