Jump to content
  • Advertisement

Archived

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

orbano

BMP Load Problem

This topic is 5420 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
Guest Anonymous Poster
check out padding on bitmap files?

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!