Thread: Parsing the Windows BMP format ???

  1. #1
    Christer
    Guest

    Unhappy Parsing the Windows BMP format ???

    Hi all,

    I have some serious trouble parsing information from
    a graphics file in windows bmp format (256 colors).
    I have managed to open the file but when i try to read
    any of the data I always get 0.
    If I open the file in binary format in visaual c++ I
    can see that the file is correct and it starts with the
    signature BM.

    As I understand it, the (256 color) bmp consists of the 3 headers structs

    BITMAPFILEHEADER, BITMAPINFOHEADER, RGBQUAD and then the actual picture data.

    I suspect this is were something goes wrong:

    ...
    ifstream fIn;
    BITMAPFILEHEADER fileHeader;

    ...

    fIn.read((char*) &fileHeader, sizeof(BITMAPFILEHEADER));

    However my struct fileHeader is terrible empty...eventhough the above
    statement should copy sizeof(BITMAPFILEHEADER) bytes to the struct fileHeader...right???

    As I am a bit new to c++ I wonder how the reading should be done
    since the way I do it seems to be wrong.

    Hoping for a bit of help here...

    Best Regards,
    Christer

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Are you opening the file in binary mode? If not then do so and try again.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Christer
    Guest
    Yes, I've opened the file in binary mode.
    The problem is still there...
    /Christer

  4. #4
    christer
    Guest
    hi again,

    here is the error check when opening the file:

    fIn.open("test.bmp", ios::binary);
    if (!fIn.is_open()) {
    cout << "Failed to open the file " << theFileName <<"\r\n";
    return false;
    }

    Wen running the program the error message does not show so the opening should be ok.

    /Christer

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to make a windows application
    By crvenkapa in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 09:59 AM
  2. Script errors - bool unrecognized and struct issues
    By ulillillia in forum Windows Programming
    Replies: 10
    Last Post: 12-18-2006, 04:44 AM
  3. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM
  4. Lil Anti Windows Humor
    By RoD in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 10-02-2002, 12:01 PM
  5. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM