使用Python可视化有压缩格式的Bitmap BMP图像调色板数据
- 参考文章
- 一、调色板数据
- 二、测试代码
- 三、测试结果
参考文章
- 有压缩格式的Bitmap(BMP)图像显示调色板数据和图像数据
- Bitmap(BMP)图像信息分析主要说明带压缩的形式
- Bitmap(BMP)图像信息验证
一、调色板数据
Color Palette Table Info ==> Start:54 Size:688 Group:172
-------------------------------------------Color Palette Table(ARGB)--------------------------------------------00 01 02 03 04 05 06 07 08 09
----------------------------------------------------------------------------------------------------------------
00000000 00FF0000 00FB0000 00F80000 00F70000 00F60000 00F50000 00F40000 00F30000 00F20000 00F10000
00000010 00EB0000 00E50000 00DF0000 00DC0000 00DB0000 00D70000 00D50000 00D30000 00D20000 00D10000
00000020 00CE0000 00C90000 00C80000 00C50000 00C40000 00C00000 00BF0000 00BE0000 00B80000 00B70000
00000030 00B60000 00B30000 00B10000 00AE0000 00AA0000 00A70000 00A40000 009F0000 009A0000 00990000
00000040 00980000 008F0000 008B0000 008A0000 00880000 00870000 00850000 00840000 00800000 00770101
00000050 00750101 00740101 00710101 006F0101 006E0101 006C0101 006A0101 00690101 00680101 00670101
00000060 00660101 00630101 005F0101 005B0101 005A0101 00530101 00510101 004B0101 00440101 00420101
00000070 00410101 003E0101 003B0101 00390101 00380101 00370101 00350101 00340101 00330101 00310101
00000080 002F0101 002D0101 002B0101 002A0101 00290101 00280101 00260101 00250101 00220101 00200101
00000090 001E0101 001C0101 001B0101 001A0101 00190101 00170101 00160101 00150101 00140101 00130101
00000100 00120101 00110101 00100101 000E0101 000D0101 000C0101 000B0101 00090101 00080101 00070101
00000110 00060101 00040101 00020101 00FFFFFF 00F6F6F6 00F3F3F3 00EDEDED 00ECECEC 00E6E6E6 00DADADA
00000120 00D9D9D9 00D6D6D6 00D0D0D0 00C0C0C0 00BEBEBE 00B8B8B8 00AFAFAF 00AEAEAE 00A9A9A9 00A5A5A5
00000130 00989898 008C8C8C 00878787 007F7F7F 007B7B7B 00767676 00757575 00737373 006E6E6E 00686868
00000140 00676767 00616161 00595959 00515151 00505050 004F4F4F 004B4B4B 00474747 00434343 00424242
00000150 00404040 003D3D3D 00333333 00323232 002D2D2D 002A2A2A 00282828 00252525 00242424 001B1B1B
00000160 00181818 00151515 000E0E0E 000D0D0D 00080808 00070707 00050505 00030303 00020202 00010101
00000170 00FFFFFF 00000000
----------------------------------------------------------------------------------------------------------------
二、测试代码
from PIL import Image, ImageDraw
import matplotlib.pyplot as plt
import numpy as np
import datetime
import shutil
import osdef main():#调色板数据colors_tab = \['#00FF0000','#00FB0000','#00F80000','#00F70000','#00F60000','#00F50000','#00F40000','#00F30000','#00F20000','#00F10000','#00EB0000','#00E50000','#00DF0000','#00DC0000','#00DB0000','#00D70000','#00D50000','#00D30000','#00D20000','#00D10000','#00CE0000','#00C90000','#00C80000','#00C50000','#00C40000','#00C00000','#00BF0000','#00BE0000','#00B80000','#00B70000','#00B60000','#00B30000','#00B10000','#00AE0000','#00AA0000','#00A70000','#00A40000','#009F0000','#009A0000','#00990000','#00980000','#008F0000','#008B0000','#008A0000','#00880000','#00870000','#00850000','#00840000','#00800000','#00770101','#00750101','#00740101','#00710101','#006F0101','#006E0101','#006C0101','#006A0101','#00690101','#00680101','#00670101','#00660101','#00630101','#005F0101','#005B0101','#005A0101','#00530101','#00510101','#004B0101','#00440101','#00420101','#00410101','#003E0101','#003B0101','#00390101','#00380101','#00370101','#00350101','#00340101','#00330101','#00310101','#002F0101','#002D0101','#002B0101','#002A0101','#00290101','#00280101','#00260101','#00250101','#00220101','#00200101','#001E0101','#001C0101','#001B0101','#001A0101','#00190101','#00170101','#00160101','#00150101','#00140101','#00130101','#00120101','#00110101','#00100101','#000E0101','#000D0101','#000C0101','#000B0101','#00090101','#00080101','#00070101','#00060101','#00040101','#00020101','#00FFFFFF','#00F6F6F6','#00F3F3F3','#00EDEDED','#00ECECEC','#00E6E6E6','#00DADADA','#00D9D9D9','#00D6D6D6','#00D0D0D0','#00C0C0C0','#00BEBEBE','#00B8B8B8','#00AFAFAF','#00AEAEAE','#00A9A9A9','#00A5A5A5','#00989898','#008C8C8C','#00878787','#007F7F7F','#007B7B7B','#00767676','#00757575','#00737373','#006E6E6E','#00686868','#00676767','#00616161','#00595959','#00515151','#00505050','#004F4F4F','#004B4B4B','#00474747','#00434343','#00424242','#00404040','#003D3D3D','#00333333','#00323232','#002D2D2D','#002A2A2A','#00282828','#00252525','#00242424','#001B1B1B','#00181818','#00151515','#000E0E0E','#000D0D0D','#00080808','#00070707','#00050505','#00030303','#00020202','#00010101','#00FFFFFF','#00000000']#颜色块的大小color_block_height = 100color_block_width = 100#每行显示颜色数num_columns = 10# 取整的行数num_rows = (len(colors_tab) + num_columns - 1) // num_columns# 创建空的颜色矩阵# color_matrix = np.zeros((num_rows * color_block_height, num_columns * color_block_width, 3), dtype=int) #背景为黑色color_matrix = np.full((num_rows * color_block_height, num_columns * color_block_width, 3), 255, dtype=int) #背景为黑色# 将颜色填充到矩阵中for i, argb in enumerate(colors_tab):# 将ARGB颜色转化为RGBa = int(argb[1:3], 16)r = int(argb[3:5], 16)g = int(argb[5:7], 16)b = int(argb[7:9], 16)color = [r, g, b]# 计算当前颜色块的位置row = i // num_columnscol = i % num_columns# 填充相应的颜色块区域x0 = row * color_block_heighty0 = (row + 1) * color_block_heightx1 = col * color_block_widthy1 = (col + 1) * color_block_widthcolor_matrix[x0:y0, x1:y1] = color#显示调色板plt.title('Bitmap Color Palette Info') #标题plt.imshow(color_matrix)plt.savefig('Bitmap_Color_Palette_Info.png', dpi=500, bbox_inches="tight") #保存图片plt.show()if __name__ == '__main__':main()
三、测试结果