Pictures calculated the share size of the buffer

Article Directory


In programming, sometimes encounter read the image from a hardware problem, then you need to allocate memory for pictures in memory for storing pictures read.

The formula

Allocate memory for the picture you need to calculate the size of the picture.

  • 图片所占内存大小 =图片长度(像素) * 图片宽度(像素) * 一个像素所占内存空间(单位:字节)

  • 图像中的像素总数=图片长度(像素) * 图片宽度(像素)

  • 一个像素所占内存空间(单位:字节)=图像深度÷8

  • 图片所占内存大小=图像中的像素总数×图像深度÷8

Specific example:

16bit computing picture read from a capture card 640 * 512 share content?

图片所占内存大小=图片长度(像素) * 图片宽度(像素) * 图像深度÷8

Namely: Image share memory size = 640 * 512 * (16 ÷ 8) = 655360Byte

  • 1M=1024KB
  • 1KB=1024B

Therefore: 655360Byte = 655360/1024 = 640KB = 0.625M

He published 194 original articles · won praise 95 · views 80000 +

Guess you like

Origin blog.csdn.net/qq_41498261/article/details/104895919