Thread: how to create a greyscale bitmap using setpixel(32-bit_value)

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    12

    how to create a greyscale bitmap using setpixel(32-bit_value)

    Hello. I am generating a bitmap picture from a binary file. I am using SetPixel(unsigned long RGB_colour) to display the binary data on the screen.

    The problem is that the values are 16 bit (that means that the value can have 64000 different color aspects). and, I whant to display the picture in black and white (greytones), not in all the colours of the rainbow.

    The method I use so far is to make my 16 bit value into an 32 bit value that fits in the SetPixel(32-bit-value) = setpixel(transparancy, red, green, blue)

    But as I said, this only gives me a colourful image.

    Hope you guys understand what I am trying to do her...

    Kristian

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Once you have the red green and blue components, you can convert them to a simple grey scale picture by using...

    Code:
    NewGreen = NewRed = NewBlue = ((OldBlue + OldRed + OldGreen)/3);
    ... and pass the new values to SetPixel. That is very simple to do, but very slightly distorts the colour because it over states the red and blue components, (the human eye is less sensitive to the red and blue ends than the green middle frequency). If that is not good enough let me know and I'll give you another, eye sensitivity weighted way to do it.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Create a Bitmap
    By SuperNewbie in forum Windows Programming
    Replies: 2
    Last Post: 03-16-2004, 09:43 AM
  2. How to create and display a bitmap programatically?
    By solar3147 in forum Windows Programming
    Replies: 4
    Last Post: 06-24-2003, 02:55 AM
  3. difficult bitmap question
    By Mecnels in forum Windows Programming
    Replies: 1
    Last Post: 03-13-2003, 07:03 AM
  4. screenshots before a window pops up?
    By MadHatter in forum Game Programming
    Replies: 13
    Last Post: 12-31-2002, 11:09 AM
  5. graphics in win32 API
    By bennyandthejets in forum Windows Programming
    Replies: 4
    Last Post: 10-03-2002, 01:10 AM