《》Bmp文件格式研究
Bmp文件内容一般由三部分连接而成:文件头、调色板、像素
文件头的格式:
9×9×2Color
424D62000000000000003E00000028000000090000000900000001
0001000000000024000000120B0000120B00000200000002000000
9×9×16Color
424DBE000000000000007600000028000000090000000900000001
0004000000000048000000120B0000120B00001000000010000000
9×9×256Color
424DA2040000000000003604000028000000090000000900000001
000800000000006C000000120B0000120B00000001000000010000
9×9×24BitColor
424D32010000000000003600000028000000090000000900000001
00180000000000FC000000120B0000120B00000000000000000000
调色板的格式:
2Color
FFFFFF00
00000000
16Color
00000000
00008000
00800000
00808000
80000000
80008000
80800000
C0C0C000
80808000
0000FF00
00FF0000
00FFFF00
FF000000
FF00FF00
FFFF0000
FFFFFF00
256Color
//ColorTable 256 4*8*8Color
00000000
40000000
80000000
FF000000
00200000
40200000
80200000
FF200000
00400000
40400000
80400000
FF400000
00600000
40600000
80600000
FF600000
00800000
40800000
80800000
FF800000
00A00000
40A00000
80A00000
FFA00000
00C00000
40C00000
80C00000
FFC00000
00FF0000
40FF0000
80FF0000
FFFF0000
00002000
40002000
80002000
FF002000
00202000
40202000
80202000
FF202000
00402000
40402000
80402000
FF402000
00602000
40602000
80602000
FF602000
00802000
40802000
80802000
FF802000
00A02000
40A02000
80A02000
FFA02000
00C02000
40C02000
80C02000
FFC02000
00FF2000
40FF2000
80FF2000
FFFF2000
00004000
40004000
80004000
FF004000
00204000
40204000
80204000
FF204000
00404000
40404000
80404000
FF404000
00604000
40604000
80604000
FF604000
00804000
40804000
80804000
FF804000
00A04000
40A04000
80A04000
FFA04000
00C04000
40C04000
80C04000
FFC04000
00FF4000
40FF4000
80FF4000
FFFF4000
00006000
40006000
80006000
FF006000
00206000
40206000
80206000
FF206000
00406000
40406000
80406000
FF406000
00606000
40606000
80606000
FF606000
00806000
40806000
80806000
FF806000
00A06000
40A06000
80A06000
FFA06000
00C06000
40C06000
80C06000
FFC06000
00FF6000
40FF6000
80FF6000
FFFF6000
00008000
40008000
80008000
FF008000
00208000
40208000
80208000
FF208000
00408000
40408000
80408000
FF408000
00608000
40608000
80608000
FF608000
00808000
40808000
80808000
FF808000
00A08000
40A08000
80A08000
FFA08000
00C08000
40C08000
80C08000
FFC08000
00FF8000
40FF8000
80FF8000
FFFF8000
0000A000
4000A000
8000A000
FF00A000
0020A000
4020A000
8020A000
FF20A000
0040A000
4040A000
8040A000
FF40A000
0060A000
4060A000
8060A000
FF60A000
0080A000
4080A000
8080A000
FF80A000
00A0A000
40A0A000
80A0A000
FFA0A000
00C0A000
40C0A000
80C0A000
FFC0A000
00FFA000
40FFA000
80FFA000
FFFFA000
0000C000
4000C000
8000C000
FF00C000
0020C000
4020C000
8020C000
FF20C000
0040C000
4040C000
8040C000
FF40C000
0060C000
4060C000
8060C000
FF60C000
0080C000
4080C000
8080C000
FF80C000
00A0C000
40A0C000
80A0C000
FFA0C000
00C0C000
40C0C000
80C0C000
FFC0C000
00FFC000
40FFC000
80FFC000
FFFFC000
0000FF00
4000FF00
8000FF00
FF00FF00
0020FF00
4020FF00
8020FF00
FF20FF00
0040FF00
4040FF00
8040FF00
FF40FF00
0060FF00
4060FF00
8060FF00
FF60FF00
0080FF00
4080FF00
8080FF00
FF80FF00
00A0FF00
40A0FF00
80A0FF00
FFA0FF00
00C0FF00
40C0FF00
80C0FF00
FFC0FF00
00FFFF00
40FFFF00
80FFFF00
FFFFFF00
像素(即数据部分)的格式:
2Color (8=1*8)*9
FFFFFFFF
80FFFFFF
90FFFFFF
B8FFFFFF
ECFFFFFF
86FFFFFF
83FFFFFF
80FFFFFF
FFFFFFFF
16Color (16=2*8)*9
DDDDDDDDD0000000
DDDDDDDDD0000000
DDFFDDDDD0000000
DDFFDDDDD0000000
DDFFFFFDD0000000
DDFFDFFDD0000000
DDFFFFFDD0000000
DDDDDDDDD0000000
DDDDDDDDD0000000
256Color (24=3*8)*9
B6B6B6B6B6B6B6B6B6000000
B6B6B6B6B6B6B6B6B6000000
B6B6B6B6B6B6B6B6B6000000
B6B6B6B6B6B6B6B6B6000000
B6B6B6B6B6B6B6B6B6000000
B6B6B6B6B6B6B6B6B6000000
B6B6B6B6B6B6B6B6B6000000
B6B6B6B6B6B6B6B6B6000000
B6B6B6B6B6B6B6B6B6000000
24BitColor (56=7*8)*9
C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C000
C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C000
C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C000
C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C000
C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C000
C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C000
C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C000
C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C000
C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C000
16色数值对应表
000000 // clBlack = '0'
000080 // clMaroon = '1'
008000 // clGreen = '2'
008080 // clOlive = '3'
800000 // clNavy = '4'
800080 // clPurple = '5'
808000 // clTeal = '6'
C0C0C0 // clSilver = '7'
808080 // clGray = '8'
0000FF // clRed = '9'
00FF00 // clLime = 'A'
00FFFF // clYellow = 'B'
FF0000 // clBlue = 'C'
FF00FF // clFuchsia = 'D'
FFFF00 // clAqua = 'E'
FFFFFF // clWhite = 'F'
一张图片是由以上三部分的数据串联而成的,既然你的长宽已知,就可以确定文件头。
确定颜色就可以确定调色板。文件头加上数据就可以成为图片。