【问题标题】:Drawable.setColorFilter() not working on Android 2.1Drawable.setColorFilter() 在 Android 2.1 上不起作用
【发布时间】:2011-07-26 20:35:57
【问题描述】:
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 错误?

【问题讨论】:

    标签: android


    【解决方案1】:

    您需要使您的 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 上看到这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-23
      • 2017-08-05
      相关资源
      最近更新 更多