0

我想在 24 位 bmp 图像上找到蓝色区域。我怎样才能找到蓝色通道?访问蓝色通道的方法是什么?

4

2 回答 2

3

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!

于 2012-01-09T10:24:57.587 回答
0

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

...从这里

于 2012-01-09T10:04:03.187 回答