PDA

Click to See Complete Forum and Search --> : Help: Converting Colour BitBlts to Monochrome


shaunpudwell
Feb 28th, 2002, 03:13 AM
:cool: I have a colour screen, either 8, 16, 24 or 32 bpp and want to blt part of the screen into a memory DC. I want to be able to
convert the image to monochrome before saving it to disk.

1. Is there a way of converting a Blt from one colour format to another.

2. Is there a way of applying some form of dithering to the image before its saved to disk.

3. Can Windows handle the conversion or would I have to dabble with the raw bitmap data using C / C++.

Any ideas would be very gratefully appreciated.
Thanks in advance

Shaun Pudwell.

plenderj
Feb 28th, 2002, 03:21 AM
Hmmm I know that SetStretchBltMode() has a Black and White parameter that might do it for you.
Then use StretchBlt instead of BitBlt, but just make sure that the source and destination rectangles are the same dimensions ya know...

riis
Feb 28th, 2002, 03:37 AM
If Plenderj's suggested method doesn't work, you can resort to pixel by pixel conversion, using the GetPixel and SetPixelV API-calls.

Color to RGB conversion can be done by the formula:
M = 0.33 * R + 0.50 * G + 0.17 * B, in which M = monochrome value, R = red, G = green, B = blue
The factors are taking in account the brightness of pure red, green or blue.

The GetPixel method gives you a color value. To extract RGB-values you can use:
R = (Color and &HFF&)
G = (Color and &HFF00&) \ &H100&
B = (Color and &HFF0000) \ &H10000

(Don't forget to include the ampersands at the end of the hexadecimal values in the R- and G-extraction formula's)

Probably this will be considerably slower than an eventual available API call, but it's nice to experimentate with it :)

shaunpudwell
Feb 28th, 2002, 04:51 AM
I'm doing a pixel by pixel scan at the moment in C++, but Set and GetPixel functions are very slow. I need a faster way of doing this, as its way to slow.

Is it possible to copy a colour bitmap into a DIB Section with a different colour format, e.g. monochrome. If so, does Windows handle the conversion for me or just assume that everything that's not background colour must therefore be black?

Shaun.