Drawable.setColorFilter() not working on Android 2.1

后端 未结 1 963
不知归路
不知归路 2020-12-19 10:32
Drawable d = new BitmapDrawable(BitmapFactory.decodeResource(
    getResources(), R.drawable.ic_watch));
d.setColorFilter(new LightingColorFilter(color, lightenColor         


        
1条回答
  •  一向
    一向 (楼主)
    2020-12-19 10:58

    You need to make your Bitmap mutable.

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

    You can see this problem cropping up over here, too.

    0 讨论(0)
提交回复
热议问题