How To Read Bitmap Files? - Programmers Heaven

Howdy, Stranger!

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

Categories

How To Read Bitmap Files?

stuckatonestuckatone Posts: 3Member
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

  • KDivad LeahcimKDivad Leahcim Posts: 3,948Member
    : 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]
    :

    3 things:

    Make sure your file is opened in binary mode and not text mode.

    Use code and /code between [ and ] to preserve spacing and set your code apart. Look for a stylecodes link at the bottom of any page you can post on for more info.

    Try posting in the C++ board and not the (Q)Basic board.
  • PuzzlerPuzzler Posts: 208Member
    Hi!

    Check out http://www.wotsit.org/ for file format info... Also, make sure you have the ios::bin option on the file open, never load the data directly into a strcut (do it one leement at a time), and make sure your sizes are right...

    --------------------------------------------
    I will bend your mind with my spoon...

Sign In or Register to comment.