我需要从图像中提取原始alpha,以便将其传递给应用程序以用作不透明蒙版。预期的格式是每像素8字节无符号整数。我怎么能用ImageMagick做到这一点?我尝试了convert image.png image.a
,但.a文件似乎没有正确的数据。
使用ImageMagick提取alpha的最佳方法是什么?理想情况下,这适用于支持alpha或透明度的任何输入图像格式。
答案 0 :(得分:3)
试试这个:
$ convert -size 16x16 xc:none -draw "stroke black fill red circle 8,8 4,4" circle_on_transparent_bg.png
$ convert circle_on_transparent_bg.png -channel A -separate -depth 8 gray:image_alpha.raw
$ od -t x1 image_alpha.raw
0000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*
0000040 00 00 00 00 00 01 20 89 be 8a 20 01 00 00 00 00
0000060 00 00 00 00 10 ff ff ff ff ff ff ff 12 00 00 00
0000100 00 00 00 13 ff ff ff ff ff ff ff ff ff 11 00 00
0000120 00 00 01 ff ff ff ff ff ff ff ff ff ff ff 01 00
0000140 00 00 21 ff ff ff ff ff ff ff ff ff ff ff 1f 00
0000160 00 00 8d ff ff ff ff ff ff ff ff ff ff ff 89 00
0000200 00 00 c0 ff ff ff ff ff ff ff ff ff ff ff ff 00
0000220 00 00 8b ff ff ff ff ff ff ff ff ff ff ff 93 00
0000240 00 00 21 ff ff ff ff ff ff ff ff ff ff ff 24 00
0000260 00 00 01 ff ff ff ff ff ff ff ff ff ff ff 01 00
0000300 00 00 00 10 ff ff ff ff ff ff ff ff ff 11 00 00
0000320 00 00 00 00 12 ff ff ff ff ff ff ff 10 00 00 00
0000340 00 00 00 00 00 01 23 91 c4 8e 22 01 00 00 00 00
0000360 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0000400
答案 1 :(得分:2)
试试这个:
convert image.png -channel A -separate image_alpha.png
嗯,这很简单:你拿alpha通道并将其保存到另一个文件。脚本输出具有1通道png(每像素8字节)。