How to calculate bitmap file size?

限于喜欢 提交于 2019-12-25 06:26:18

问题


  1. How to find size in byte of 50 x 50 RGB color image?
  2. If the above image saved in BMP file with 54 bytes of header size, what is the total size of that BMP file?
  3. How to know the content of every bytes in BMP file?
  4. And how to know the hexadecimal value of it?

回答1:


  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).

  2. 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.

  3. 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.

  4. 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.



来源:https://stackoverflow.com/questions/36682379/how-to-calculate-bitmap-file-size

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!