BMP Load Problem
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
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement