Solved

How do I programatically determine the byte length of a windows BITMAP?

Posted on 2015-01-10
3
177 Views
Last Modified: 2015-01-10
Hi:

I'm building a windows utility application that works with bitmaps.

If I have an HBITMAP or LPBITMAP, how do I determine the byte count of the actual image?

Is it inferred from bmBitsPixel * bmWidth * bmHeight?

Thanks,
JohnB
0
Comment
Question by:jxbma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 40542543
>> Is it inferred from bmBitsPixel * bmWidth * bmHeight?

In short: Yes, that is exactly it. Or, almost, since you have to round up 'bmBitsPerPixel' to the next byte boundary and divide it by 8 to get the actual number of bytes the color information is taking up. Then you multiply that value with the dimensions (or width and height),.
0
 
LVL 86

Expert Comment

by:jkr
ID: 40542581
Um, it's actually a bit simpler than 'rounding up':

DWORD dwBmpSize = ((bm.bmBitsPixe / 8) + 1) * bm.bmWidth * bm.bmHeight;

Open in new window

0
 
LVL 1

Author Closing Comment

by:jxbma
ID: 40542720
Once again. Cool. Thx
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question