Jump to content
  • Advertisement

Archived

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

Buiden

How to determine dimensions of a bitmap?

This topic is 5301 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

Hey this might seem like a really stupid question, since I have only been at DirectX for a couple months now. I have been using the D3DXCreateTextureFromFileEx function to create textures from .bmp files. For the width/height parameters I pass D3DX_DEFAULT and it pulls the width/height from the file. Well I am wondering what the fastest/best way to pull the width/height of the bitmap from a file for my own use. I know that it can be done using windows GDI but I am wondering if there is a less painful method of doing so. Thanks, _Buiden

Share this post


Link to post
Share on other sites
Advertisement
Read the file as binary data. The first chunk of the file should correspond with a BITMAPFILEHEADER structure, after the BITMAPFILEHEADER should be a BITMAPINFOHEADER. The BITMAPINFOHEADER has the height and width as data members. You should have access to both struct definitions if you include windows.h.

Share this post


Link to post
Share on other sites
Or, you could just open the file up and read in 2 long values (shorts work as well).

long Width,Height;
FILE *in = fopen(BitmapFileName,"rb");
fseek(in,18,0); //Seek to position 18, from start of file!
fread(&Width,4,1,in);
fread(&Height,4,1,in);
fclose(in);

Or with shorts:
short Width,Height;
FILE *in = fopen(BitmapFileName,"rb");
fseek(in,18,0); //Seek to position 18, from start of file!
fread(&Width,2,1,in);
fseek(in,22,0); //Seek to position 22, from start of file!
fread(&Height,2,1,in);
fclose(in);

Nice and easy, and it only requires reading in 4-8 bytes of data .

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!