Archived

This topic is now archived and is closed to further replies.

orbano

BMP Load Problem

Recommended Posts

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

Share this post


Link to post
Share on other sites
orbano    130
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

Share this post


Link to post
Share on other sites
orbano    130
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

Share this post


Link to post
Share on other sites