如何获取位图的颜色深度并计算其大小(以Ko为单位)? [英] How do I get the color depth of a bitmap and calculate its size (in Ko) ?

查看:496
本文介绍了如何获取位图的颜色深度并计算其大小(以Ko为单位)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



让我解释一下我想做什么。我从相机中获取快照并将其保存到位图对象中,但不将其保存在磁盘上。我想计算那个位图的大小(在o或Ko中),在某处,我发现了这个公式:



大小(以Ko表示)=(宽*高度*颜色深度)/(每像素位数* 1024)



在其他地方我找到了颜色深度的公式:



颜色深度= 2 ^(每像素的位数)



我对这一切有点困惑。我想知道是否真的可以获得位图的大小(在Ko或任何八位字节中)而不保存它。



我检查了系统.Drawing.Imaging.PixelFormat我从相机获得的快照值有32bppArgb(我想如果我理解我的位图中每像素有32位的话)。



谢谢。

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.

推荐答案

您可以粗略估计位图的大小:

You can get a rough estimate of the size of a bitmap:
Bytes = Width * height * (BitsPerPixel / 8)

但这并不准确:Bitmap文件包含框架和其他信息(例如调色板,宽度和高度信息)也占据了空间。一个位图对象也有其他成员也使用内存空间。



如果你把它作为原始字节得到它将是正确的:

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:

MemoryStream ms = new MemoryStream();
imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Bmp);
byte[] rawData =  ms.ToArray();




Dim ms As New MemoryStream()
imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
Dim rawData As Byte() = ms.ToArray()


这篇关于如何获取位图的颜色深度并计算其大小(以Ko为单位)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆