color.xml中的android位图颜色

时间:2013-03-04 16:52:45

标签: android colors bitmap

我想将位图颜色设置为src。但我的颜色没有显示,只是空屏幕。我试图做

mIcon11 = BitmapFactory.decodeResource(getResources(), R.color.grey);

如果我写R.drawable.imageName它会显示图像,为什么我的颜色没有显示?

我的颜色是:

<resources>
<color name="grey">#696969</color>
</resources>

2 个答案:

答案 0 :(得分:3)

作为Bitmap

int bitmapWidth = ...
int bitmapHeight = ....
Bitmap mIcon11 = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
mIcon11.eraseColor(getResources().getColor(R.color.grey));


由于它是一种颜色,因此您不需要Bitmap。您可能最好只将其加载为Drawable

Drawable mIcon11 = getResources().getDrawable(R.color.grey);

答案 1 :(得分:-1)