bmp 24 位文件格式的蓝色通道
我想在 24 位 bmp 图像上找到蓝色区域。我怎样才能找到蓝色通道?访问蓝色通道的方式有哪些?
I want to find blue areas on 24 bit bmp image. How can i find the blue color channel ? What is the ways of accessing the blue color channel ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
24 位位图 (.bmp) 图像的标头为 54 字节。之后是像素数据。每个像素使用 3 个字节:按顺序蓝色、绿色、红色。
要看到这一点,请在绘画中制作一个 1x1 像素图像并将一个像素设置为蓝色。如果您在十六进制编辑器中查看 .bmp 文件,您将看到第 55 个字节的值为 FF(蓝色),而后面的 2 个字节为 00(没有绿色,没有红色)。当然,如果您编写一个读取所有字节的 C 程序,您也可以看到这一点。如果打印从第 55 个字节到末尾的值,您将看到相同的结果。
像素数据需要对齐,这称为步幅。步幅计算如下:
在 3x3 bmp 中,步幅将为 (3 * 24) / 8 = 9。该值需要四舍五入为可被 4 整除的数字(本例中为 12),因此需要 3 个额外字节每行正确对齐位。因此,如果所有字节都是蓝色,则在 54 字节之后,您将得到:
对于 4x4 bmp,步长 = (4 * 24) / 8 = 12。12 可以被 4 整除,因此不需要额外的字节。对于 5x5 bmp,步长 = (5 * 24) / 8 = 15,因此每行需要 1 个额外字节。
要了解有关 bmp 文件格式的更多信息,请查看此维基百科页面。希望这有帮助!
A 24-bits bitmap (.bmp) image has a header of 54 bytes. After that comes the pixeldata. Per pixel, 3 bytes are used: blue, green, red, in that order.
To see this, make a 1x1 pixel image in paint and make the one pixel blue. If you view the .bmp file in a hexeditor you'll see the 55th byte has the value FF (blue), while the 2 after that are 00 (no green, no red). Ofcourse you can also see this if you write a C program that reads all the bytes. If you print the values from the 55th byte till the end, you'll see the same.
The pixeldata needs to be aligned, this is called stride. Stride is calculated as follow:
In a 3x3 bmp, stride will be (3 * 24) / 8 = 9. This value needs to be rounded up to a number divisible by 4 (12 in this case), so you need 3 extra bytes per row to correctly align the bits. So if all bytes are blue, after the 54 byte you will have:
For a 4x4 bmp, stride = (4 * 24) / 8 = 12. 12 is divisible by 4, so there are no extra bytes needed. For a 5x5 bmp, stride = (5 * 24) / 8 = 15, so 1 extra byte is needed per row.
To find out more info about the bmp file format, check out this wikipedia page. Hope this helps!
...来自此处。
...from here.