Sign in to follow this  

Bitmap size

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

Do you mean the size of the image? Are you using the Bitmap class in GDI+? If so, what about using GetWidth() * GetHeight() * bpp ? (You can get the bpp by using GetPixelFormat() and then checking the returned value).

That said, I don't know how the bitmap class stores the data (chances are it uses 4 bpp for a 3bpp image as well, for performace reasons). In addition, images usually have lines longer that xres (or better, xres and a row length don't need to be equal. Most of the times this value is available in the library.

If you want to know the size of the BITMAP object (that is the size of the c++ object), you may use sizeof(BITMAP) but:
-the result will not include pixel data (pixels are refered with a pointer).
-Result also takes into account padding used for alignment (IIRC)

EDIT: if you want to know the size of the image data (first case) another option is to open the file (if it is a bmp) and read the header (BITMAPINFOHEADER) section. From there you should be able to get the pixels data size.

EDIT 2: I've just noticed that there is a BITMAP structure in GDI. Here yopu have a bmWidthBytes value. Multiply it with the bmHeight and you have your pixels size in bytes.

Share this post


Link to post
Share on other sites

This topic is 3372 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this