how do I read the data in a bitmap file? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

how do I read the data in a bitmap file?

I am presently working on a project that requires all the image data of a monochrome bitmap file be stored in a array. I have no idea how to do this.

This is my present code which spits out garbage:

'''''
FILE *filePointer2;

filePointer2 = fopen(temp2,"rb"); //temp2 holds the present filename
//there is 1000 .bmp files to be
//opened and read, this has been
//successfully completed my only
//problem is reading in the "raw
//data" of each bitmap file

fgets(tempHolder2,200,filePointer2);
cout << tempHolder2;

''''

I'm using MS Visual C++ 6.0. Any advice/help would be great! Please note this idea of reading data from a image file is completely new to me; I have no experience. Thanks in advance!

[email protected]

Comments

  • gautamgautam Posts: 642Member
    [b][red]This message was edited by the gautam at 2002-4-12 4:20:53[/red][/b][hr]
    [b][red]This message was edited by the gautam at 2002-4-12 4:18:58[/red][/b][hr]
    I am not sure but I think it will be in the following way

    [code]
    BITMAPFILEHEADER bf;
    BITMAPINFOHEADER bi;

    // open the file in binary mode
    ....
    // read in the file header info
    fread(&bf, 1, sizeof(BITMAPFILEHEADER), fp);

    // do the test and etc to check if its a bitmap
    ....

    // read in the info header - if you are looking for portability then
    // you shouldn't trust the sizeof and you should calculate the sizes
    // of structure beforehand

    fread(&bi, 1, sizeof(BITMAPINFOHEADER), fp);
    ....

    // check for monochrome - bitcount = 1
    ....
    // if bitcount <= 8 then we have a color table, so we need to read in the color table.
    ......

    // if we have pixel imformation - we read that in to an array
    .....

    // close the file
    .....

    [/code]


    You should look at the bitmap file format for more information. Also note that the bitmap is generally saved upside down - so you might have to flip it.

    : I am presently working on a project that requires all the image data of a monochrome bitmap file be stored in a array. I have no idea how to do this.
    :
    : This is my present code which spits out garbage:
    :
    : '''''
    : FILE *filePointer2;
    :
    : filePointer2 = fopen(temp2,"rb"); //temp2 holds the present filename
    : //there is 1000 .bmp files to be
    : //opened and read, this has been
    : //successfully completed my only
    : //problem is reading in the "raw
    : //data" of each bitmap file
    :
    : fgets(tempHolder2,200,filePointer2);
    : cout << tempHolder2;
    :
    : ''''
    :
    : I'm using MS Visual C++ 6.0. Any advice/help would be great! Please note this idea of reading data from a image file is completely new to me; I have no experience. Thanks in advance!
    :
    : [email protected]
    :





Sign In or Register to comment.