如何用ImageMagick将少色彩色图转为无损8位像素BMP?
解决方案
ImageMagick 命令行方案
问题核心是ImageMagick会根据图像颜色数量自动选择最小位深(当颜色数≤16时默认生成4位BMP),你需要强制指定生成8位每像素的调色板BMP,使用以下命令:
convert input_image.ext -type Palette -colors 256 -define bmp:bits-per-pixel=8 -depth 8 output.bmp
-type Palette:明确生成调色板类型的图像-colors 256:预留足够的调色板容量,确保原图像颜色能完整保留-define bmp:bits-per-pixel=8:强制BMP格式使用8位每像素,覆盖自动选择的4位逻辑-depth 8:确保每个像素的位深为8位
其他命令行工具方案
GraphicsMagick
与ImageMagick语法兼容,命令逻辑一致:
gm convert input_image.ext -type Palette -colors 256 -define bmp:bits-per-pixel=8 -depth 8 output.bmp
FFmpeg
通过指定pal8像素格式直接生成8位索引BMP,自动提取原图像所有颜色生成调色板:
ffmpeg -i input_image.ext -c:v bmp -pix_fmt pal8 output.bmp
只要原图像颜色数≤256,就能保证转换无损。
内容的提问来源于stack exchange,提问作者Chris
相关产品推荐
相关产品推荐

