如何计算位图文件的大小? [英] How to calculate bitmap file size?

查看:763
本文介绍了如何计算位图文件的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 如何找到50 x 50 RGB彩色图像的字节大小?
  2. 如果上面的图像保存在标头大小为54字节的BMP文件中,那么该BMP文件的总大小是多少?
  3. 如何知道BMP文件中每个字节的内容?
  4. 如何知道它的十六进制值?

推荐答案

  1. 假设您是指内存中的需求,则所需的最小内存量将为50 * 50 * 3(width * height * numComponents),对于RGB则为7500字节.但是,填充每条扫描线的速度可能更快,例如填充到偶数个32位实体,从而使实际需求更高.另外,图形卡最好采用ARGB格式的值,在这种情况下,应为50 * 50 * 4(= 10000).

  1. Assuming you mean in-memory requirements, the minimum amount of memory needed would be 50 * 50 * 3 (width * height * numComponents), or 7500 bytes for RGB. However, it might be faster to pad each scanline, for example to an even number of 32 bit entities, making the the actual requirement higher. Also, it may be better for the graphics card to have the values in ARGB format, in which case it would be 50 * 50 * 4 (= 10000).

这取决于BMP文件中使用的压缩,但是如果没有压缩,我认为最小值应为54 + 50 * 50 * 4或10054字节,因为BMP通常存储为每个像素32位.请注意,BMP文件的有效标头大小不同,可以存储索引(调色板)图像以及16位图像,因此上述内容仅适用于未经压缩的普通32位/像素真彩色" BMP.

It depends on the compression used in the BMP file, but if there's no compression I think the minimum would 54 + 50 * 50 * 4, or 10054 bytes, as BMPs are typically stored as 32 bits per pixel. Note that BMP files have different sizes of valid headers, can store indexed (palette) images, and also 16 bit images so the above will hold only for normal, uncompressed 32 bit/pixel "true color" BMPs.

阅读规范,您应该了解它的工作原理.要查看实际文件示例的内容,请在十六进制查看器/编辑器或其他工具中打开它,以查看文件的二进制内容.

Read the specification, and you should understand how it works. To see the contents of an actual file sample, open it in a hex viewer/editor or other tool that allows you to see the binary contents of the file.

十六进制只是值的另一种表示形式,与十进制或八进制相对.例如,如果字节值为十进制的255,则十六进制为FF.

Hexadecimal is just a different representation of the values, as opposed to decimal or octal. If the byte value is 255 decimal, it will be FF in hexadecimal, for example.

这篇关于如何计算位图文件的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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