修改 BMP 调色板并保存为正确格式

Posted

技术标签:

【中文标题】修改 BMP 调色板并保存为正确格式【英文标题】:Modifying BMP color palette and saving as correct format 【发布时间】:2018-09-14 20:52:26 【问题描述】:

一个旧的废弃软件游戏使用图像的调色板作为游戏的调色板 https://ufile.io/su465

Windows 10 无法将其识别为具有文件类型,但使用在线文件类型检查器会提示其为具有 DIB 文件头的 Windows 3.x BMP 文件。我会很感激帮助我弄清楚如何修改这个文件的调色板并能够以(相同)正确的格式保存它,以便游戏仍然可以读取它。

初步实验表明,它可以使用 GIMP 等编辑器打开,调色板已更改,并保存为 .bmp 图像,但我找不到任何生成与原始格式相同的 .bmp 的设置,因此读错了。

【问题讨论】:

您听说过 OneDrive 和 Dropbox,对吧?我不知道 ufile.io 是谁,但他们的网站让我毛骨悚然。 :) 另外,您只需将.bmp 扩展名添加到文件中,所有您喜欢的编辑器都会识别它。 您在寻找图像处理工具建议吗?这个问题是题外话。 【参考方案1】:

您可以使用 ImageMagick 加载图像并更改一些颜色,但它会对调色板进行大规模更改,并且不会以与原始图像相同的方式将其存储回来,所以我怀疑您的游戏会加载它。

相反,您可以像这样使用 ImageMagick 转储调色板:

identify -verbose palette.bmp

输出

Image: palette.bmp
  Format: BMP3 (Microsoft Windows bitmap image (V3))
  Class: PseudoClass
  Geometry: 23x23+0+0
  Resolution: 28.34x28.34
  Print size: 0.811574x0.811574
  Units: PixelsPerCentimeter
  Colorspace: sRGB
  Type: Palette
  Base type: Undefined
  Endianess: Undefined
  Depth: 8-bit
  Channel depth:
    Red: 8-bit
    Green: 8-bit
    Blue: 8-bit
  Channel statistics:
    Pixels: 529
    Red:
      min: 0  (0)
      max: 255 (1)
      mean: 147.877 (0.57991)
      standard deviation: 79.3755 (0.311277)
      kurtosis: -1.08138
      skewness: -0.716658
      entropy: 0.829558
    Green:
      min: 0  (0)
      max: 255 (1)
      mean: 137.873 (0.54068)
      standard deviation: 67.4838 (0.264642)
      kurtosis: -0.62805
      skewness: -0.58513
      entropy: 0.8385
    Blue:
      min: 0  (0)
      max: 255 (1)
      mean: 127.45 (0.499804)
      standard deviation: 68.6364 (0.269162)
      kurtosis: -0.63322
      skewness: -0.190579
      entropy: 0.842021
  Image statistics:
    Overall:
      min: 0  (0)
      max: 255 (1)
      mean: 137.733 (0.540131)
      standard deviation: 71.8319 (0.281694)
      kurtosis: -0.913123
      skewness: -0.483209
      entropy: 0.836693
  Colors: 65
  Histogram:
        32: (  0,  0,  0) #000000 black
        18: (  7,  7,  7) #070707 srgb(7,7,7)
         1: ( 13, 16, 41) #0D1029 srgb(13,16,41)
         1: ( 14, 14, 14) #0E0E0E srgb(14,14,14)
        44: ( 33, 65, 43) #21412B srgb(33,65,43)
        11: ( 38, 88, 71) #265847 srgb(38,88,71)
         3: ( 47, 94, 43) #2F5E2B srgb(47,94,43)
         3: ( 51, 51, 51) #333333 grey20
         7: ( 54, 56, 67) #363843 srgb(54,56,67)
        12: ( 58, 58, 58) #3A3A3A srgb(58,58,58)
         1: ( 58, 62, 74) #3A3E4A srgb(58,62,74)
         1: ( 63, 68, 80) #3F4450 srgb(63,68,80)
         2: ( 66, 66, 66) #424242 grey26
         1: ( 70, 70, 70) #464646 srgb(70,70,70)
         1: ( 73, 80, 93) #49505D srgb(73,80,93)
         2: ( 76, 76, 76) #4C4C4C srgb(76,76,76)
         2: ( 81, 81, 81) #515151 srgb(81,81,81)
         1: ( 82, 37, 20) #522514 srgb(82,37,20)
         1: ( 83, 93,105) #535D69 srgb(83,93,105)
         1: ( 86, 86, 86) #565656 srgb(86,86,86)
         1: ( 90, 60, 49) #5A3C31 srgb(90,60,49)
         5: ( 91, 91, 91) #5B5B5B srgb(91,91,91)
         1: ( 96, 96, 96) #606060 srgb(96,96,96)
         4: ( 98,112,125) #62707D srgb(98,112,125)
         1: (101,101,101) #656565 srgb(101,101,101)
         1: (106, 69, 66) #6A4542 srgb(106,69,66)
         1: (111,111,111) #6F6F6F srgb(111,111,111)
         2: (114,158,140) #729E8C srgb(114,158,140)
         1: (116,160,182) #74A0B6 srgb(116,160,182)
        11: (117, 89, 74) #75594A srgb(117,89,74)
         2: (117,117,117) #757575 grey46
         3: (117,182,232) #75B6E8 srgb(117,182,232)
         1: (121,142, 97) #798E61 srgb(121,142,97)
         9: (126,140,134) #7E8C86 srgb(126,140,134)
         1: (150,138,112) #968A70 srgb(150,138,112)
         2: (159,119,115) #9F7773 srgb(159,119,115)
         9: (165,148,142) #A5948E srgb(165,148,142)
        28: (167,167,177) #A7A7B1 srgb(167,167,177)
         1: (168,144,105) #A89069 srgb(168,144,105)
        10: (172,169,143) #ACA98F srgb(172,169,143)
        16: (172,198,213) #ACC6D5 srgb(172,198,213)
         6: (174,150,111) #AE966F srgb(174,150,111)
         4: (176,184,155) #B0B89B srgb(176,184,155)
         4: (181,156,116) #B59C74 srgb(181,156,116)
         6: (187,162,122) #BBA27A srgb(187,162,122)
         3: (192,228,231) #C0E4E7 srgb(192,228,231)
         5: (194,169,127) #C2A97F srgb(194,169,127)
         8: (195,128,148) #C38094 srgb(195,128,148)
         6: (195,190,182) #C3BEB6 srgb(195,190,182)
         1: (199,194,187) #C7C2BB srgb(199,194,187)
        36: (200,175,133) #C8AF85 srgb(200,175,133)
         1: (202,132,153) #CA8499 srgb(202,132,153)
        26: (207,181,138) #CFB58A srgb(207,181,138)
        34: (213,147,144) #D59390 srgb(213,147,144)
        16: (213,187,144) #D5BB90 srgb(213,187,144)
        13: (214,141,163) #D68DA3 srgb(214,141,163)
        30: (216,240,255) #D8F0FF srgb(216,240,255)
         7: (220,194,150) #DCC296 srgb(220,194,150)
         5: (221,145,168) #DD91A8 srgb(221,145,168)
         1: (223,218,212) #DFDAD4 srgb(223,218,212)
        35: (226,190,172) #E2BEAC srgb(226,190,172)
         3: (227,149,173) #E395AD srgb(227,149,173)
         2: (227,222,216) #E3DED8 srgb(227,222,216)
        21: (231,226,221) #E7E2DD srgb(231,226,221)
         1: (255,255,255) #FFFFFF white
  Colormap entries: 256
  Colormap:
         0: (255,255,255,255) #FFFFFFFF white
         1: (128,  0,  0,255) #800000FF maroon
         2: (  0,128,  0,255) #008000FF green
         3: (128,128,  0,255) #808000FF olive
         4: (  0,  0,128,255) #000080FF navy
         5: (128,  0,128,255) #800080FF purple
         6: (  0,128,128,255) #008080FF teal
         7: (192,192,192,255) #C0C0C0FF silver
         8: (192,204,216,255) #C0CCD8FF srgba(192,204,216,1)
         9: (  0,  0,  0,255) #000000FF black
        10: (231,226,221,255) #E7E2DDFF srgba(231,226,221,1)
        11: (227,222,216,255) #E3DED8FF srgba(227,222,216,1)     <--- LOOK HERE
        12: (223,218,212,255) #DFDAD4FF srgba(223,218,212,1)
        13: (219,214,208,255) #DBD6D0FF srgba(219,214,208,1)
        14: (215,210,204,255) #D7D2CCFF srgba(215,210,204,1)
        15: (211,206,199,255) #D3CEC7FF srgba(211,206,199,1)
        16: (207,202,195,255) #CFCAC3FF srgba(207,202,195,1)
        17: (203,198,191,255) #CBC6BFFF srgba(203,198,191,1)
        18: (199,194,187,255) #C7C2BBFF srgba(199,194,187,1)
        19: (195,190,182,255) #C3BEB6FF srgba(195,190,182,1)
        20: (117,117,117,255) #757575FF grey46
        21: (111,111,111,255) #6F6F6FFF srgba(111,111,111,1)
        22: (106,106,106,255) #6A6A6AFF srgba(106,106,106,1)
        23: (101,101,101,255) #656565FF srgba(101,101,101,1)
        24: ( 96, 96, 96,255) #606060FF srgba(96,96,96,1)
        25: ( 91, 91, 91,255) #5B5B5BFF srgba(91,91,91,1)
        26: ( 86, 86, 86,255) #565656FF srgba(86,86,86,1)
        27: ( 81, 81, 81,255) #515151FF srgba(81,81,81,1)
        28: ( 76, 76, 76,255) #4C4C4CFF srgba(76,76,76,1)
        29: ( 70, 70, 70,255) #464646FF srgba(70,70,70,1)
        30: ( 66, 66, 66,255) #424242FF grey26
        31: ( 58, 58, 58,255) #3A3A3AFF srgba(58,58,58,1)
        32: ( 51, 51, 51,255) #333333FF grey20
        33: ( 44, 44, 44,255) #2C2C2CFF srgba(44,44,44,1)
        34: ( 36, 36, 36,255) #242424FF grey14
        35: ( 29, 29, 29,255) #1D1D1DFF srgba(29,29,29,1)
        36: ( 22, 22, 22,255) #161616FF srgba(22,22,22,1)
        37: ( 14, 14, 14,255) #0E0E0EFF srgba(14,14,14,1)
        38: (  7,  7,  7,255) #070707FF srgba(7,7,7,1)
        39: (  0,  0,  0,255) #000000FF black
        40: (220,194,150,255) #DCC296FF srgba(220,194,150,1)
        41: (213,187,144,255) #D5BB90FF srgba(213,187,144,1)
        42: (207,181,138,255) #CFB58AFF srgba(207,181,138,1)
        43: (200,175,133,255) #C8AF85FF srgba(200,175,133,1)
        44: (194,169,127,255) #C2A97FFF srgba(194,169,127,1)
        45: (187,162,122,255) #BBA27AFF srgba(187,162,122,1)
        46: (181,156,116,255) #B59C74FF srgba(181,156,116,1)
        47: (174,150,111,255) #AE966FFF srgba(174,150,111,1)
        48: (168,144,105,255) #A89069FF srgba(168,144,105,1)
        49: (162,137, 99,255) #A28963FF srgba(162,137,99,1)
        50: (135, 65, 34,255) #874122FF srgba(135,65,34,1)
        51: (127, 61, 32,255) #7F3D20FF srgba(127,61,32,1)
        52: (119, 57, 30,255) #77391EFF srgba(119,57,30,1)
        53: (112, 53, 28,255) #70351CFF srgba(112,53,28,1)
        54: (104, 49, 26,255) #68311AFF srgba(104,49,26,1)
        55: ( 97, 45, 24,255) #612D18FF srgba(97,45,24,1)
        56: ( 89, 41, 22,255) #592916FF srgba(89,41,22,1)
        57: ( 82, 37, 20,255) #522514FF srgba(82,37,20,1)
        58: ( 74, 33, 18,255) #4A2112FF srgba(74,33,18,1)
        59: ( 66, 29, 16,255) #421D10FF srgba(66,29,16,1)
        60: (180,115, 22,255) #B47316FF srgba(180,115,22,1)
        61: (175,109, 19,255) #AF6D13FF srgba(175,109,19,1)
        62: (170,104, 17,255) #AA6811FF srgba(170,104,17,1)
        63: (165, 99, 14,255) #A5630EFF srgba(165,99,14,1)
        64: (161, 94, 12,255) #A15E0CFF srgba(161,94,12,1)
        65: (156, 88,  9,255) #9C5809FF srgba(156,88,9,1)
        66: (151, 83,  7,255) #975307FF srgba(151,83,7,1)
        67: (147, 78,  4,255) #934E04FF srgba(147,78,4,1)
        68: (142, 73,  2,255) #8E4902FF srgba(142,73,2,1)
        69: (137, 68,  0,255) #894400FF srgba(137,68,0,1)
        70: (240,158,183,255) #F09EB7FF srgba(240,158,183,1)
        71: (233,153,178,255) #E999B2FF srgba(233,153,178,1)
        72: (227,149,173,255) #E395ADFF srgba(227,149,173,1)
        73: (221,145,168,255) #DD91A8FF srgba(221,145,168,1)
        74: (214,141,163,255) #D68DA3FF srgba(214,141,163,1)
        75: (208,136,158,255) #D0889EFF srgba(208,136,158,1)
        76: (202,132,153,255) #CA8499FF srgba(202,132,153,1)
        77: (195,128,148,255) #C38094FF srgba(195,128,148,1)
        78: (189,124,143,255) #BD7C8FFF srgba(189,124,143,1)
        79: (183,119,139,255) #B7778BFF srgba(183,119,139,1)
        80: (168, 41,  1,255) #A82901FF srgba(168,41,1,1)
        81: (164, 40,  1,255) #A42801FF srgba(164,40,1,1)
        82: (159, 39,  1,255) #9F2701FF srgba(159,39,1,1)
        83: (155, 38,  1,255) #9B2601FF srgba(155,38,1,1)
        84: (151, 37,  1,255) #972501FF srgba(151,37,1,1)
        85: (146, 36,  1,255) #922401FF srgba(146,36,1,1)
        86: (142, 35,  1,255) #8E2301FF srgba(142,35,1,1)
        87: (138, 34,  1,255) #8A2201FF srgba(138,34,1,1)
        88: (133, 33,  1,255) #852101FF srgba(133,33,1,1)
        89: (129, 32,  1,255) #812001FF srgba(129,32,1,1)
        90: (107, 74, 12,255) #6B4A0CFF srgba(107,74,12,1)
        91: (101, 68, 11,255) #65440BFF srgba(101,68,11,1)
        92: ( 96, 62, 11,255) #603E0BFF srgba(96,62,11,1)
        93: ( 91, 57, 11,255) #5B390BFF srgba(91,57,11,1)
        94: ( 86, 51, 11,255) #56330BFF srgba(86,51,11,1)
        95: ( 81, 45, 10,255) #512D0AFF srgba(81,45,10,1)
        96: ( 76, 39, 10,255) #4C270AFF srgba(76,39,10,1)
        97: ( 71, 34, 10,255) #47220AFF srgba(71,34,10,1)
        98: ( 66, 28, 10,255) #421C0AFF srgba(66,28,10,1)
        99: ( 60, 22,  9,255) #3C1609FF srgba(60,22,9,1)
       100: (166,138, 56,255) #A68A38FF srgba(166,138,56,1)
       101: (162,133, 55,255) #A28537FF srgba(162,133,55,1)
       102: (158,129, 55,255) #9E8137FF srgba(158,129,55,1)
       103: (154,125, 55,255) #9A7D37FF srgba(154,125,55,1)
       104: (150,120, 54,255) #967836FF srgba(150,120,54,1)
       105: (147,116, 54,255) #937436FF srgba(147,116,54,1)
       106: (143,112, 54,255) #8F7036FF srgba(143,112,54,1)
       107: (139,107, 53,255) #8B6B35FF srgba(139,107,53,1)
       108: (135,103, 53,255) #876735FF srgba(135,103,53,1)
       109: (132, 98, 53,255) #846235FF srgba(132,98,53,1)
       110: ( 98,112,125,255) #62707DFF srgba(98,112,125,1)
       111: ( 93,105,118,255) #5D6976FF srgba(93,105,118,1)
       112: ( 88, 99,112,255) #586370FF srgba(88,99,112,1)
       113: ( 83, 93,105,255) #535D69FF srgba(83,93,105,1)
       114: ( 78, 87, 99,255) #4E5763FF srgba(78,87,99,1)
       115: ( 73, 80, 93,255) #49505DFF srgba(73,80,93,1)
       116: ( 68, 74, 86,255) #444A56FF srgba(68,74,86,1)
       117: ( 63, 68, 80,255) #3F4450FF srgba(63,68,80,1)
       118: ( 58, 62, 74,255) #3A3E4AFF srgba(58,62,74,1)
       119: ( 54, 56, 67,255) #363843FF srgba(54,56,67,1)
       120: (154,142,115,255) #9A8E73FF srgba(154,142,115,1)
       121: (150,138,112,255) #968A70FF srgba(150,138,112,1)
       122: (147,135,109,255) #93876DFF srgba(147,135,109,1)
       123: (144,132,107,255) #90846BFF srgba(144,132,107,1)
       124: (140,129,104,255) #8C8168FF srgba(140,129,104,1)
       125: (137,126,102,255) #897E66FF srgba(137,126,102,1)
       126: (134,123, 99,255) #867B63FF srgba(134,123,99,1)
       127: (130,120, 97,255) #827861FF srgba(130,120,97,1)
       128: (127,117, 94,255) #7F755EFF srgba(127,117,94,1)
       129: (124,113, 91,255) #7C715BFF srgba(124,113,91,1)
       130: ( 85,171, 87,255) #55AB57FF srgba(85,171,87,1)
       131: ( 60,161, 71,255) #3CA147FF srgba(60,161,71,1)
       132: ( 21,153, 23,255) #159917FF srgba(21,153,23,1)
       133: ( 53,131, 54,255) #358336FF srgba(53,131,54,1)
       134: ( 48,123, 28,255) #307B1CFF srgba(48,123,28,1)
       135: ( 16,121, 25,255) #107919FF srgba(16,121,25,1)
       136: ( 39, 98, 23,255) #276217FF srgba(39,98,23,1)
       137: ( 47, 94, 43,255) #2F5E2BFF srgba(47,94,43,1)
       138: ( 19, 92, 20,255) #135C14FF srgba(19,92,20,1)
       139: ( 16, 65, 17,255) #104111FF srgba(16,65,17,1)
       140: ( 43, 97,195,255) #2B61C3FF srgba(43,97,195,1)
       141: ( 56, 70,227,255) #3846E3FF srgba(56,70,227,1)
       142: ( 51, 59,255,255) #333BFFFF srgba(51,59,255,1)
       143: ( 51, 67,206,255) #3343CEFF srgba(51,67,206,1)
       144: ( 22, 26,215,255) #161AD7FF srgba(22,26,215,1)
       145: ( 46, 60,182,255) #2E3CB6FF srgba(46,60,182,1)
       146: ( 22, 28,169,255) #161CA9FF srgba(22,28,169,1)
       147: ( 42, 66,144,255) #2A4290FF srgba(42,66,144,1)
       148: ( 25, 34,119,255) #192277FF srgba(25,34,119,1)
       149: ( 17, 25, 83,255) #111953FF srgba(17,25,83,1)
       150: (216,240,255,255) #D8F0FFFF srgba(216,240,255,1)
       151: (172,224,255,255) #ACE0FFFF srgba(172,224,255,1)
       152: (153,214,255,255) #99D6FFFF srgba(153,214,255,1)
       153: (130,202,255,255) #82CAFFFF srgba(130,202,255,1)
       154: (117,182,232,255) #75B6E8FF srgba(117,182,232,1)
       155: (104,192,255,255) #68C0FFFF srgba(104,192,255,1)
       156: ( 81,150,220,255) #5196DCFF srgba(81,150,220,1)
       157: ( 24,156,206,255) #189CCEFF srgba(24,156,206,1)
       158: ( 86,139,185,255) #568BB9FF srgba(86,139,185,1)
       159: ( 30,137,169,255) #1E89A9FF srgba(30,137,169,1)
       160: (235,237,167,255) #EBEDA7FF srgba(235,237,167,1)
       161: (234,235,144,255) #EAEB90FF srgba(234,235,144,1)
       162: (209,204,119,255) #D1CC77FF srgba(209,204,119,1)
       163: (247,244,  0,255) #F7F400FF srgba(247,244,0,1)
       164: (237,232, 50,255) #EDE832FF srgba(237,232,50,1)
       165: (195,196, 11,255) #C3C40BFF srgba(195,196,11,1)
       166: (195,195, 52,255) #C3C334FF srgba(195,195,52,1)
       167: (159,162, 23,255) #9FA217FF srgba(159,162,23,1)
       168: (159,159, 67,255) #9F9F43FF srgba(159,159,67,1)
       169: (110,122, 46,255) #6E7A2EFF srgba(110,122,46,1)
       170: (255,255,255,255) #FFFFFFFF white
       171: (192,228,231,255) #C0E4E7FF srgba(192,228,231,1)
       172: (172,198,213,255) #ACC6D5FF srgba(172,198,213,1)
       173: (167,167,177,255) #A7A7B1FF srgba(167,167,177,1)
       174: (160,160,168,255) #A0A0A8FF srgba(160,160,168,1)
       175: (116,160,182,255) #74A0B6FF srgba(116,160,182,1)
       176: (131,153,177,255) #8399B1FF srgba(131,153,177,1)
       177: (131,153,177,255) #8399B1FF srgba(131,153,177,1)
       178: (128,152,176,255) #8098B0FF srgba(128,152,176,1)
       179: (128,152,176,255) #8098B0FF srgba(128,152,176,1)
       180: (226,190,172,255) #E2BEACFF srgba(226,190,172,1)
       181: (213,147,144,255) #D59390FF srgba(213,147,144,1)
       182: (215,118,110,255) #D7766EFF srgba(215,118,110,1)
       183: (184,115,103,255) #B87367FF srgba(184,115,103,1)
       184: (159,119,115,255) #9F7773FF srgba(159,119,115,1)
       185: (162,106, 93,255) #A26A5DFF srgba(162,106,93,1)
       186: (137,100, 88,255) #896458FF srgba(137,100,88,1)
       187: (152, 87, 77,255) #98574DFF srgba(152,87,77,1)
       188: (106, 69, 66,255) #6A4542FF srgba(106,69,66,1)
       189: ( 90, 60, 49,255) #5A3C31FF srgba(90,60,49,1)
       190: (114,158,140,255) #729E8CFF srgba(114,158,140,1)
       191: (  0,128,128,255) #008080FF teal
       192: ( 66,122,117,255) #427A75FF srgba(66,122,117,1)
       193: (  0,128,128,255) #008080FF teal
       194: ( 57,120, 96,255) #397860FF srgba(57,120,96,1)
       195: ( 61, 90, 99,255) #3D5A63FF srgba(61,90,99,1)
       196: ( 38, 88, 71,255) #265847FF srgba(38,88,71,1)
       197: ( 33, 65, 43,255) #21412BFF srgba(33,65,43,1)
       198: ( 18, 57, 48,255) #123930FF srgba(18,57,48,1)
       199: (255,255,255,255) #FFFFFFFF white
       200: (255,255,255,255) #FFFFFFFF white
       201: (244,246,216,255) #F4F6D8FF srgba(244,246,216,1)
       202: (233,216,194,255) #E9D8C2FF srgba(233,216,194,1)
       203: ( 44, 95, 89,255) #2C5F59FF srgba(44,95,89,1)
       204: (211,244,197,255) #D3F4C5FF srgba(211,244,197,1)
       205: (196,211,159,255) #C4D39FFF srgba(196,211,159,1)
       206: (255,199, 26,255) #FFC71AFF srgba(255,199,26,1)
       207: (176,184,155,255) #B0B89BFF srgba(176,184,155,1)
       208: (175,177,119,255) #AFB177FF srgba(175,177,119,1)
       209: (165,148,142,255) #A5948EFF srgba(165,148,142,1)
       210: (172,169,143,255) #ACA98FFF srgba(172,169,143,1)
       211: (215,160, 20,255) #D7A014FF srgba(215,160,20,1)
       212: (198,127,  8,255) #C67F08FF srgba(198,127,8,1)
       213: (202,110, 70,255) #CA6E46FF srgba(202,110,70,1)
       214: (121,142, 97,255) #798E61FF srgba(121,142,97,1)
       215: (153,126, 77,255) #997E4DFF srgba(153,126,77,1)
       216: (128,128,128,255) #808080FF fractal
       217: (101,155, 42,255) #659B2AFF srgba(101,155,42,1)
       218: (  0,203, 22,255) #00CB16FF srgba(0,203,22,1)
       219: (167,108, 57,255) #A76C39FF srgba(167,108,57,1)
       220: (255, 66,  0,255) #FF4200FF srgba(255,66,0,1)
       221: (151,100, 66,255) #976442FF srgba(151,100,66,1)
       222: (153,101, 42,255) #99652AFF srgba(153,101,42,1)
       223: (221, 52,106,255) #DD346AFF srgba(221,52,106,1)
       224: ( 41, 68,117,255) #294475FF srgba(41,68,117,1)
       225: ( 88,105,181,255) #5869B5FF srgba(88,105,181,1)
       226: ( 66,107,132,255) #426B84FF srgba(66,107,132,1)
       227: ( 80,100,128,255) #506480FF srgba(80,100,128,1)
       228: (117, 89, 74,255) #75594AFF srgba(117,89,74,1)
       229: (254, 24, 20,255) #FE1814FF srgba(254,24,20,1)
       230: (110, 92, 43,255) #6E5C2BFF srgba(110,92,43,1)
       231: (156, 66, 57,255) #9C4239FF srgba(156,66,57,1)
       232: (184, 50, 66,255) #B83242FF srgba(184,50,66,1)
       233: (136, 68, 66,255) #884442FF srgba(136,68,66,1)
       234: ( 85, 68,127,255) #55447FFF srgba(85,68,127,1)
       235: (126,140,134,255) #7E8C86FF srgba(126,140,134,1)
       236: (207, 16, 12,255) #CF100CFF srgba(207,16,12,1)
       237: (146, 25, 20,255) #921914FF srgba(146,25,20,1)
       238: ( 51, 47, 18,255) #332F12FF srgba(51,47,18,1)
       239: ( 17, 40, 14,255) #11280EFF srgba(17,40,14,1)
       240: ( 13, 16, 41,255) #0D1029FF srgba(13,16,41,1)
       241: (  0,  0,  0,255) #000000FF black
       242: (  0,  0,  0,255) #000000FF black
       243: (  0,  0,  0,255) #000000FF black
       244: (  0,  0,  0,255) #000000FF black
       245: (255,255,255,255) #FFFFFFFF white
       246: ( 80,100,128,255) #506480FF srgba(80,100,128,1)
       247: (  0,  0,  0,255) #000000FF black
       248: (128,128,128,255) #808080FF fractal
       249: (255,  0,  0,255) #FF0000FF red
       250: (  0,255,  0,255) #00FF00FF lime
       251: (255,255,  0,255) #FFFF00FF yellow
       252: (  0,  0,255,255) #0000FFFF blue
       253: (255,  0,255,255) #FF00FFFF magenta
       254: (  0,255,255,255) #00FFFFFF cyan
       255: (  0,  0,  0,255) #000000FF black
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Matte color: grey74
  Background color: white
  Border color: srgb(223,223,223)
  Transparent color: none
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 23x23+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: None
  Orientation: Undefined
  Properties:
    date:create: 2018-04-05T08:00:58+01:00
    date:modify: 2018-04-05T07:59:56+01:00
    signature: e403caa8a487c57943e3cdce3370485abb3ce54e045b0342a9e5826f5a9fe3ad
  Artifacts:
    verbose: true
  Tainted: False
  Filesize: 1630B
  Number pixels: 529
  User time: 0.000u
  Elapsed time: 0:01.000
  Version: ImageMagick 7.0.7-28 Q16 x86_64 2018-03-27 http://www.imagemagick.org

我在上面用&lt;--- LOOK HERE 注释了调色板(颜色图)条目。

如果您将文件加载到十六进制编辑器中,例如在线编辑器here,您可以找到该条目及其周围的条目,然后尽情地玩弄它们!

我已将调色板中的相应条目标记为红色。请注意,调色板条目都有一个多余的 FF 用于 ImageMagick 中的透明度,因此您不会在十六进制中看到 FF

所以,让我们制作一个该颜色的样本 (#E3DED8):

convert -size 100x40 xc:"#E3DED8" swatch.gif

并在十六进制转储中用洋红色替换它,看看会发生什么:

【讨论】:

【参考方案2】:

这是一个 23x23 位图,每个像素使用 1 个字节。

文件的前 14 个字节是 BITMAP 标头本身。 (黄色)

随后的 40 个字节是 DIB 标头,表示序列化的BITMAPINFOHEADER 结构,该结构将图像标识为不使用压缩且每像素 8 位的 23x23 图像。 (红色下划线)

接下来的 1024 字节是调色板。 256 个条目。每个条目占用 4 个字节。那是一个 RGB(或者是 BGR?),后跟零字节。 (蓝色)

然后是图像字节,即 23 行,每行 24 字节。行必须在 4 字节边界上对齐。 (黑色)

因此,如果您想替换图像调色板,请使用您自己的调色板数据填充从偏移量0x36 开始的 1024 字节。

【讨论】:

以上是关于修改 BMP 调色板并保存为正确格式的主要内容,如果未能解决你的问题,请参考以下文章

使用 PHP GD 库从 BMP 获取像素的调色板

VC自绘图形怎么保存成BMP或者JPG格式?

关于BMP

BMP 图像信息隐藏及检测

BMP文件结构(转)

使用程序集制作屏幕截图