Computer Graphics

Moderators: Sephiroth
Number of threads: 1241
Number of posts: 2641

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
how do I read the data in a bitmap file? Posted by stuckatone on 11 Apr 2002 at 11:38 PM
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!

stuckatone@yahoo.com
Report
Re: how do I read the data in a bitmap file? Posted by gautam on 12 Apr 2002 at 4:02 AM
This message was edited by the gautam at 2002-4-12 4:20:53

This message was edited by the gautam at 2002-4-12 4:18:58

I am not sure but I think it will be in the following way

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
.....




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!
:
: stuckatone@yahoo.com
:








 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.