获取BMP文件的像素值
我有一个关于读取 bmp 图像的问题。如何获取 bmp 图像中的像素值(R、G、B 值)? 谁能帮我使用C语言编程?
i got a question for reading an bmp image. How can i get the pixel value(R, G, B values) in an bmp image?
Can anyone help me using the C programming language?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
注意:如果您的 BMP 有 Alpha 通道,您可能需要为 Alpha 值获取额外的字节。在这种情况下,图像将为
image[pixelcount][4]
,并且您将添加另一个getc(streamIn)
行来保存第四个索引。结果我的 BMP 不需要这个。〜Locutus
Note: you may need to grab an extra byte for the alpha values if your BMP has alpha channel. In that case image would be
image[pixelcount][4]
, and you would add anothergetc(streamIn)
line to hold that fourth index. My BMP turned out to not need that.~Locutus
最简单的方法是为您选择的平台找到一个好的图像处理库并使用它。
困难的方法是打开文件并实际解释其中的二进制数据。为此,您需要 BMP 文件规范。我建议先尝试简单的方法。
The easy way would be to find a good image manipulation library for your chosen platform and use that.
The hard way would be to open the file and actually interpret the binary data within. To do that you'll need the BMP File Specification. I'd recommend trying the easy way first.
你需要研究BMP文件格式。读取未压缩的 24 位 BMP 文件更容易。它们只包含开头的标题和每个像素的 RGB 值。
首先,请查看 http://en.wikipedia.org/wiki/ 中的 2x2 位图图像示例BMP_文件_格式。请按照以下步骤操作。
字节分别为 0、0 和 255。 (不确定顺序是否是RGB。我很久以前就做过了,我认为顺序不是RGB。只需验证一下即可。)
就这么简单!研究 BMP 的标头以了解有关该格式的更多信息。
You need to study the BMP file format. It is easier to read uncompressed 24-bit BMP files. They just contain a header at the beginning and RGB values of each pixel.
To start with this, check the example of 2x2 bitmap image at http://en.wikipedia.org/wiki/BMP_file_format. Follow the below steps.
The bytes would be 0, 0 and 255 respectively. (Not sure whether the order is RGB. I had done this long back and I think the order is not RGB. Just verify this.)
As simple as that! Study the header of the BMP to understand more about the format.