Skip to main content
gamedev.net
🔒 Locked

BMP Load Problem

Started by orbano Jan 17, 2004 at 4:38 PM 3 replies 900+ views
Original Post
orbano
orbano
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
tHiSiSbOb
tHiSiSbOb
Can we see some code? Sounds really weird...
----------------------------------------------------"Plant a tree. Remove a Bush" -A bumper sticker I saw.
orbano
orbano
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[b][c][1]),1,1,fp);
fread(&(Texture[b][c][0]),1,1,fp);
Texture[b][c][3]=255;
}
fclose(fp);
}


"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
orbano
orbano
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.