BMP Load Problem

Started by
3 comments, last by orbano 20 years, 3 months ago
Hi! I wrote a function that loads an uncompressed 24bit windows bitmap file. I can easily load files created with Paint, but when i edit my pictures in other programs, or simly copy-paste something to paint, that is not created with it, and then save, the bmp loaded is corrupted (the whole picture, or the part of it is black). The new file''s size is the same as the one, that is loaded correctly. Any ideas? Thanks in advance! "Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin
"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin
Advertisement
Can we see some code? Sounds really weird...
----------------------------------------------------"Plant a tree. Remove a Bush" -A bumper sticker I saw.
check out padding on bitmap files?
what is padding?

Some code:

void CTexture::Load(char* FileName)
{
FILE *fp;
unsigned short a;
char id[2];
int b,c;
fp=fopen(FileName,"r");
if (fp==NULL) {
GEngine_SendErrorMsg("Couldn''t open file !");
return;
}
fread(id,2,1,fp);
if (id[0]!=''B'' || id[1]!=''M'') {
GEngine_SendErrorMsg("Invalid file format !");
return;
}
fseek(fp,18,SEEK_SET);
fread(&b,4,1,fp);
fread(&c,4,1,fp);
if (b!=256 || c!=256) {
GEngine_SendErrorMsg("Invalide bitmap size !");
return;
}
fseek(fp,28,SEEK_SET);
fread(&a,2,1,fp);
if (a!=24) {
GEngine_SendErrorMsg("Invalid color depth !");
return;
}
fread(&b,4,1,fp);
if (b!=0) {
GEngine_SendErrorMsg("Compressed image !");
return;
}
fseek(fp,54,SEEK_SET);
for (c=0; c<256; c++)
for (b=0; b<256; b++) {
fread(&(Texture[c][2]),1,1,fp);
fread(&(Texture[c][1]),1,1,fp);<br> fread(&(Texture[c][0]),1,1,fp);<br> Texture[c][3]=255;<br> }<br>fclose(fp);<br>} </b> <br><br>"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin
"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin
oh, its just okay. my fault. i used acces mode "r" instead of "rb" so when there were colours aother than the standard coulours in the paint palette (the basic 16) it read them abnormally.
thank you!

"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin
"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin

This topic is closed to new replies.

Advertisement