Results 1 to 4 of 4

Thread: Help: Converting Colour BitBlts to Monochrome

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2001
    Location
    Near Sheerness in Kent, UK
    Posts
    25

    Exclamation Help: Converting Colour BitBlts to Monochrome

    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.

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    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...
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    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

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Oct 2001
    Location
    Near Sheerness in Kent, UK
    Posts
    25
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width