Thread: Create .BMP 8-bit GreyScale

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    2

    Create .BMP 8-bit GreyScale

    I can't find any examples to create a .BMP file in C given pixel information.

    The image I need to create is 10x10 resolution and is in greyscale (256 shades of grey).

    I can't even find any header structure information a 8bit greyscale (i can only find info for RGB color examples)

    Can any one please help??

    Many thanks!

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Wotsit is your buddy. Your pal. You're friend.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Quote Originally Posted by Lydecker
    I can't find any examples to create a .BMP file in C given pixel information.

    The image I need to create is 10x10 resolution and is in greyscale (256 shades of grey).

    I can't even find any header structure information a 8bit greyscale (i can only find info for RGB color examples)
    How is this a C-question? Common file formats are described here:

    http://www.wotsit.org/

    And to answer to your next and true C-question, no, a C-structure is not good to map stream information. You must read/write the data byte by byte from/to the stream to/from some internal structure.

    Good practice is to have the stream in an array of unsigned char in binary mode ("rb"/"rw") with fread() / fwrite().
    Emmanuel Delahaye

    "C is a sharp tool"

  4. #4
    Registered User
    Join Date
    Jun 2004
    Posts
    2
    So I should declare an array of chars 10 by 10 with each location containing a integer between 0 and 255 representing the shade of grey?

    I then print out to a new file using binary write the .bmp header info followed by the 10 by 10 array????

    Thanks for the help (- I' think I'm getting the idea slowly!)

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Use the 256 palletized bmp format.


    File:
    - Header
    - Palette
    - Byte data

    Also for RGB data greyscale is simply equal amounts of RGB for each color and a color reduction scheme is used to ensure there are only 256 different colors or diff shades of grey.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  2. How to create a file association program?
    By eShain in forum Windows Programming
    Replies: 1
    Last Post: 03-06-2006, 12:15 PM
  3. Cannot create MDI Client Win
    By JaWiB in forum Windows Programming
    Replies: 1
    Last Post: 10-31-2005, 10:05 PM
  4. Replies: 7
    Last Post: 12-10-2004, 08:18 AM
  5. bit patterns of negtive numbers?
    By chunlee in forum C Programming
    Replies: 4
    Last Post: 11-08-2004, 08:20 AM