bmp 24 位文件格式的蓝色通道

发布于 2024-12-25 19:48:32 字数 55 浏览 4 评论 0原文

我想在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

李不 2025-01-01 19:48:32

24 位位图 (.bmp) 图像的标头为 54 字节。之后是像素数据。每个像素使用 3 个字节:按顺序蓝色、绿色、红色。

要看到这一点,请在绘画中制作一个 1x1 像素图像并将一个像素设置为蓝色。如果您在十六进制编辑器中查看 .bmp 文件,您将看到第 55 个字节的值为 FF(蓝色),而后面的 2 个字节为 00(没有绿色,没有红色)。当然,如果您编写一个读取所有字节的 C 程序,您也可以看到这一点。如果打印从第 55 个字节到末尾的值,您将看到相同的结果。

像素数据需要对齐,这称为步幅。步幅计算如下:

stride = (width * bpp) / 8;

在 3x3 bmp 中,步幅将为 (3 * 24) / 8 = 9。该值需要四舍五入为可被 4 整除的数字(本例中为 12),因此需要 3 个额外字节每行正确对齐位。因此,如果所有字节都是蓝色,则在 54 字节之后,您将得到:

FF 00 00 FF   00 00 FF 00   00 00 00 00
FF 00 00 FF   00 00 FF 00   00 00 00 00
FF 00 00 FF   00 00 FF 00   00 00 00 00

对于 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:

stride = (width * bpp) / 8;

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:

FF 00 00 FF   00 00 FF 00   00 00 00 00
FF 00 00 FF   00 00 FF 00   00 00 00 00
FF 00 00 FF   00 00 FF 00   00 00 00 00

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!

梦里南柯 2025-01-01 19:48:32

24 位像素 (24bpp) 格式支持 16,777,216 种不同的颜色
每3字节存储1个像素值。每个像素值定义
像素的红色、绿色和蓝色样本(RGBAX 中的 8.8.8.0.0
符号)。具体按照顺序(蓝色、绿色和红色,每个 8 位)
每个样本)。

...来自此处

The 24-bit pixel (24bpp) format supports 16,777,216 distinct colors
and stores 1 pixel value per 3 bytes. Each pixel value defines the
red, green and blue samples of the pixel (8.8.8.0.0 in RGBAX
notation). Specifically in the order (blue, green and red, 8-bits per
each sample).

...from here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文