0

I want to set bitmap color as src. But my color isnt displayed, just empty screen. Im trying to do

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

If i write R.drawable.imageName it displays image, why my color isnt displayed ?

My color is:

<resources>
<color name="grey">#696969</color>
</resources>
kort.es
  • 479
  • 2
  • 7
  • 26
  • 2
    because a color is not a drawable? what you can do is create a drawable with a rectangle shape filled with your color – njzk2 Mar 04 '13 at 16:55
  • You could refer to this : http://stackoverflow.com/questions/5669501/how-to-get-rgb-values-of-bitmap-in-android – lokoko Mar 04 '13 at 17:04

2 Answers2

3

As a Bitmap:

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

.
Since it is a color, you don't really need a Bitmap. You may be better of just loading it as a Drawable:

Drawable mIcon11 = getResources().getDrawable(R.color.grey);
Streets Of Boston
  • 12,576
  • 2
  • 25
  • 28
-1

You could refer to this : how to get RGB values of bitmap in android

or

http://www.java2s.com/Code/Android/2D-Graphics/Findcomponentsofcolorofthebitmapatxy.htm

They mention how you could get the bitmap colors

Community
  • 1
  • 1
lokoko
  • 5,785
  • 5
  • 35
  • 68