views:

977

answers:

1

Hey all!

I'm working with Android and I really need a fast way to get a bitmap of a predetermined size to be filled with a predetermined colour.

The following code is not working for me however;

Bitmap input is a mutable bitmap

 int old = input.getPixel(0, 0);
 Canvas c = new Canvas(input);
 Rect rect = c.getClipBounds(); // The dimensions of the bitmap are returned
 c.drawARGB(a, r, g, b);
 int n = input.getPixel(0, 0);
 if(old==n)
  Log.e(TAG, "Values didn't change!");
 return input;

Rest assured, the 'old' value and the value of (a|r|g|b) are different but having 'drawn' the colour using a canvas with my mutable bitmap underneath, the bitmap retains it's old value.

I'd be happy with any method that takes a bitmap and a colour value and returns a bitmap filled with that colour.

Kind regards,

Gav

+2  A: 

I didn't provide enough info!

My alpha value was out of range;

int a = 0xFF<<24

So when I called

c.drawARGB(a,r,g,b);

It failed quietly and didn't change the values.

gav
This belongs as an edit to your original post.
Ben Alpert
Apologies, it was my first post. What's the etiquette to close the question if I've answered it myself?
gav
@Ben: You are wrong. When you solve a question yourself you post the solution as an answer and accept it. @Gav: On StackOverflow you generally just ask a question and leave off the hey or regards at the end as this is just noise
Casebash