|
From: balamurali m. <bal...@re...> - 2002-06-11 13:56:39
|
Sir,
I know that when u open an image file in the text mode we cant see
the image but when we open it in binary mode we should be able to
read the data from it and store it in any structure.Since this is
what my doubt is all about I present it here.
struct bitmapfileheader
{
short int signature;/*2bytes*/
int filesize;/*4bytes*/
int reserved;/*4bytes*/
int dataoffset;/*4bytes*/
};
int main()
{
bitmapfileheader bmpf;
cout<<sizeof(bmpf);
}
here the result shows the size as 16bytes instead of 14bytes
also while reading into this structure using file.open and
file.read statement always wrong data is contained in the
structure where the read data is stored.Why is this so?
There is error only while reading into the structure as a whole as
in the case
file.open("file.bmp",ios::binary|ios::in);
file.read((char*)&bmpf,sizeof(bmpf));
This always reads erroneous values into the corresponding elements
in the structure.But
file.open("file.bmp",ios::binary|ios::in);
file.read((char*)&bmpf.signature,sizeof(bmpf.signature));
file.read((char*)&bmpf.filesize,sizeof(bmpf.filesize));
file.read((char*)&bmpf.reserved,sizeof(bmpf.reserved));
file.read((char*)&bmpf.dataoffset,sizeof(bmpf.dataoffset);
this reads the correct values into the respective elements of the
structure.
why is this so?
why cant we simply read the contents of the file into the
structure using the first statement?what really happens during
this process?
I am using G++ in Linux environment.
Please help me.
_________________________________________________________
Click below to visit monsterindia.com and review jobs in India or
Abroad
http://monsterindia.rediff.com/jobs
|