Click here to Skip to main content
15,886,680 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi here,

Let e explain what i'm trying to do. I get a snap from a camera and save it into a bitmap object but do not save it on the disk. I want to calculate the size of that bitmap (in o or Ko) and somewhere, i've found this formula :

Size (in Ko) = (Width * Height * Color Depth) / (Number of bits per pixel * 1024)

Elsewhere I've found a formula of Color Depth :

Color Depth = 2^(Number of bits per pixel)

I'm a little bit confused with all this. I would like to know if it's really possible to get the size (in Ko or whatever octects) of a bitmap without saving it before.

I've checked the System.Drawing.Imaging.PixelFormat value for the snap i've got from the camera and had 32bppArgb (I suppose if i'm understanding things that there is 32 bits per pixel in my bitmap).

Thanks.
Posted

1 solution

You can get a rough estimate of the size of a bitmap:
Bytes = Width * height * (BitsPerPixel / 8)
But that won't be exact: a Bitmap file contains framing and other information (such as palettes, width and height infor) which also occupies space. A bitmap object also has other members which also use memory space.

It'll be about right for the data if you just get it as raw bytes:
C#
MemoryStream ms = new MemoryStream();
imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Bmp);
byte[] rawData =  ms.ToArray();

VB
Dim ms As New MemoryStream()
imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
Dim rawData As Byte() = ms.ToArray()
 
Share this answer
 
Comments
Olayèmi Ouabi 7-Jul-14 5:11am    
Thank you. Have a nice week !!
OriginalGriff 7-Jul-14 5:40am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900