Changing the colours in a bitmap.
Posted on 2004-11-05
Okay, what I have is:
A bitmap on a device context created by creating a blank device context and copying the bitmap to it using:
SelectObject hDC, oImage
where hDC is the device context handle and oImage is a StdPicture object.
This gives me a device context with the bitmap on it.
What I want is:
I have bitmaps in greyscale, I want to colour them in ONE colour, so that the image appears in differing shades of that colour, i.e. the original bitmap is a gradient from white to black, left to right. The function I want will apply a colour to that grey bitmap so that the outcome will be that colour to black, left to right, in a gradient of that colour in between.
Somehow to modify the colours in that bitmap WITHOUT going through each individual pixel in the bitmap, the only possible solution I have come up with myself is to access the palette somehow and modify the 256 colours in the bitmap. However, all the functions I have tried myself have either not worked or required a hPal (a handle to an existing palette), the stdPicture object has a hPal but it is always 0 because my device caps do not have/require/allow it.
The reason I want this without going through each pixel is because it will take too long, basically these images are required very quickly and may be very large so the quicker I can do it the better.
Furthermore, the images will never contain more than 256 colours if that helps.
Oh and another solution I have already tried is BitBlt-ing the bitmap (operation: SrcAnd) with a bitmap of a specific colour. With this solution if I put in 255 of red, green, blue or a combination of 255 with those colours (i.e. rgb(255,255,0) or rgb(255,0,255)), the bitmap comes out exactly how I want, but if I use rgb(129, 200, 20) or anything not uniform it does not work and the greyscale becomes fragmented into blocks of colour as if the whole bitmap had become 16 colours only. Perhaps there is a solution here and I am doing something wrong.
Anyway, there is the problem, any solutions?