6

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.

MysticMagicϡ
  • 28,593
  • 16
  • 73
  • 124
gav
  • 29,022
  • 23
  • 65
  • 90

1 Answers1

7

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
  • 29,022
  • 23
  • 65
  • 90
  • Apologies, it was my first post. What's the etiquette to close the question if I've answered it myself? – gav Jun 01 '09 at 07:42
  • 5
    @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 May 05 '10 at 06:27