
Iostream or stdio ??
Which sort of i/o is best? IOSTREAM or STDIO?
oh and could someone help me with my BMP loader, im trying to use ifstream to open it but i keep getting errors... plus C++ Builder is crap compared to VC++
Heres my lil code snippet:
BITMAPFILEHEADER bmpheaderfile ;
BITMAPINFOHEADER bmpheaderinfo ;
long imageSize;
int colorMode;
long imageIdx;
unsigned char colorSwap;
unsigned char *bmpData;
ifstream fin(filename, ios::in | ios::binary);
if(!fin)
return 0;
fin.read((char*) &bmpheaderfile, sizeof bmpheaderfile);
fin.read((char*) &bmpheaderinfo, sizeof bmpheaderinfo);
//colorMode = bmpheaderinfo.biBitCount/8;
imageSize = bmpheaderinfo.biWidth * bmpheaderinfo.biHeight * 3;
if(bmpheaderinfo.biBitCount != 24)
{
fin.close();
return 0;
}
bmpData = new unsigned char [imageSize];
fin.seekg( bmpheaderfile.bfOffBits,ios::beg);
fin.read((char*) &bmpData, sizeof bmpData);
//ead(bmpfile->imageData, sizeof(unsigned char), imageSize, fileptr);
for(imageIdx = 0; imageIdx < imageSize; imageIdx += colorMode);
{
colorSwap = bmpData[imageIdx];
bmpData[imageIdx]= bmpData[imageIdx+2];
bmpData[imageIdx+2] = colorSwap;
}
fin.close();
Wot Sig?

Wot Sig?
1: there is no better I/O. It is which ever style suits you best.
2: If you included the errors it would be more helpful for me helping you since staring at your code will get me no where(Thats just me though.)
2: If you included the errors it would be more helpful for me helping you since staring at your code will get me no where(Thats just me though.)
sorry.. the error is todo with the memory so i fink its this bit of code:
bmpData = new unsigned char [imageSize];
fin.seekg( bmpheaderfile.bfOffBits,ios::beg);
fin.read((char*) &bmpData, sizeof bmpData);
and when i delete bmpData it crashes. Maybe im not using the fstream properly?
bmpData = new unsigned char [imageSize];
fin.seekg( bmpheaderfile.bfOffBits,ios::beg);
fin.read((char*) &bmpData, sizeof bmpData);
and when i delete bmpData it crashes. Maybe im not using the fstream properly?
Wot Sig?
hi,
i think you are not allowed to "new" a char.
to allocate chars you need malloc.
so try something like:
"bmpData= malloc(sizeof(unsigned char)* imageSize);"
(i´m not sure if there have to be an pointer!)
here a note from the msdn:
"The new operator does not allocate reference types because they are not objects."
and your
"fin.read((char*) &bmpData, sizeof bmpData);"
looks strange, too.
sizeof returns the size of the datatype, so i think you need
"..., sizeof(bmpData)* imageSize);"
hope this helps...
greetings
i think you are not allowed to "new" a char.
to allocate chars you need malloc.
so try something like:
"bmpData= malloc(sizeof(unsigned char)* imageSize);"
(i´m not sure if there have to be an pointer!)
here a note from the msdn:
"The new operator does not allocate reference types because they are not objects."
and your
"fin.read((char*) &bmpData, sizeof bmpData);"
looks strange, too.
sizeof returns the size of the datatype, so i think you need
"..., sizeof(bmpData)* imageSize);"
hope this helps...
greetings
quote:
Original post by Rafflesia
i think you are not allowed to "new" a char.
Yes, you are.

February 12, 2002 07:30 AM
Just ignore what Rafflesia said. Here''s some food for thought, oh, and i''m assuming (by your code) that you''re only reading 24-bit bitmaps? If not let me know, and i''ll change some code to load 8/24 bit bitmaps.
Alright, well, this only does 24-bit bitmaps for now, and i wrote this in this little text box, so it *may* contain gramatical errors, if you need help with it, or adding to it, let me know..
Billy - BillyB@mrsnj.com
|
Alright, well, this only does 24-bit bitmaps for now, and i wrote this in this little text box, so it *may* contain gramatical errors, if you need help with it, or adding to it, let me know..
Billy - BillyB@mrsnj.com
ok, so i´m wrong. it was just a thought.
but what does ms means by:
"The new operator does not allocate reference types because they are not objects."
char and int are reference types, or is this my mistake?
greetings
but what does ms means by:
"The new operator does not allocate reference types because they are not objects."
char and int are reference types, or is this my mistake?
greetings
Wow, thanks for all ur help.
oh ans sizeof can return the number of elemnets in an array just use: sizeof array / sizeof array[0]
i fink , look it up in the help files
oh and mr annon im trying to use streams not stdio
iostreams are easier to understand in my opinion
:D
it still doesnt work i dont fink the fin.read() funstion is being used properly...
fin.read((char*) &bmpData, sizeof(bmpData)*imageSize);
i get an EAccessviolation or sumething.. Borland C++ Compiler is not very good compared to VC++ as i said...
Wot Sig?
Edited by - CEdCopy on February 12, 2002 9:41:04 AM
oh ans sizeof can return the number of elemnets in an array just use: sizeof array / sizeof array[0]
i fink , look it up in the help files
oh and mr annon im trying to use streams not stdio
iostreams are easier to understand in my opinion
:D
it still doesnt work i dont fink the fin.read() funstion is being used properly...
fin.read((char*) &bmpData, sizeof(bmpData)*imageSize);
i get an EAccessviolation or sumething.. Borland C++ Compiler is not very good compared to VC++ as i said...
Wot Sig?
Edited by - CEdCopy on February 12, 2002 9:41:04 AM
Wot Sig?
>>i get an EAccessviolation or sumething.. Borland C++ Compiler is not very good compared to VC++ as i said<<
the problem lies in your code not with borland c++. whats that saying ''a poor workman blames his tools''
http://uk.geocities.com/sloppyturds/gotterdammerung.html
the problem lies in your code not with borland c++. whats that saying ''a poor workman blames his tools''
http://uk.geocities.com/sloppyturds/gotterdammerung.html
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement