【问题标题】:Image size in MB from pixel height and pizel width像素高度和像素宽度的图像大小(以 MB 为单位)
【发布时间】:2016-11-16 22:09:41
【问题描述】:

也许是个愚蠢的问题,但是: 当您知道图像时,如何计算图像的大小(以兆字节为单位) 像素高度和像素宽度? 谢谢

【问题讨论】:

标签: c# wpf


【解决方案1】:

取决于颜色深度。如果您使用的是 8 位像素,则为:

height * width / 1048576

如果您使用的是 32 位像素,则为:

4*height*width/1048576height*width/262144

【讨论】:

  • 还要看步幅,图片是在内存中还是文件格式等。
【解决方案2】:

这是我用来获取原始位图图像大小的计算:

// Calculate the pixel depth in bytes:
int pixSize = Image.GetPixelFormatSize(myImage.PixelFormat) / 8;
int size = (myImage.Height * myImage.Width * pixSize) / 1048576;

这只是原始位图的大小。正如 Scott Jones 所提到的,这不考虑压缩的步幅(缓冲区字节中的填充)或图像格式。它只是原始位图的最小尺寸。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-18
    • 2011-12-05
    • 2014-12-06
    • 1970-01-01
    • 1970-01-01
    • 2011-08-06
    • 1970-01-01
    • 2021-03-15
    相关资源
    最近更新 更多