我正在尝试将Android应用程序资源(图标和背景)转换为相同的格式(为了节省空间并使其着色):

$ identify -verbose ic_alarm_black_48dp.png
Image: ic_alarm_black_48dp.png
Format: PNG (Portable Network Graphics)
Mime type: image/png
Class: DirectClass
Geometry: 192x192+0+0
Units: Undefined
Type: Bilevel
Base type: Bilevel
Endianess: Undefined
Colorspace: Gray
Depth: 8-bit
Channel depth:
gray: 1-bit
alpha: 8-bit该图像有8位深度和1位灰色通道深度.
下面是我想要转换为上面的格式的测试图像(一个在透明背景上有阴影的形状):

$ identify -verbose a.png
Image: a.png
Format: PNG (Portable Network Graphics)
Mime type: image/png
Class: DirectClass
Geometry: 256x256+0+0
Units: Undefined
Type: TrueColorAlpha
Endianess: Undefined
Colorspace: sRGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
alpha: 8-bit我希望得到一个1位灰度图像,8位α通道。。
我觉得我需要将源图像转换为1位灰度图像(所有非透明像素设置为1),并在顶部应用提取的alpha掩码。
转换为1位灰度
`convert a.png -alpha extract -threshold 0 -negate -transparent white a-trans.png`在顶部涂上口罩
`convert a-trans.png \( a.png -alpha extract \) -alpha off -compose copy_opacity -composite a-result.png`

$ identify -verbose a-result.png
Image: a-result.png
Format: PNG (Portable Network Graphics)
Mime type: image/png
Class: DirectClass
Geometry: 256x256+0+0
Units: Undefined
Type: Bilevel
Base type: Bilevel
Endianess: Undefined
Colorspace: Gray
Depth: 8-bit
Channel depth:
gray: 1-bit
alpha: 8-bit最后一个形象是我想要实现的。这种转换能得到优化吗?
发布于 2016-07-11 14:49:26
我想你的意思是:
convert input.png -channel RGB -fill black -colorize 100% result.png

Image: result.png
Format: PNG (Portable Network Graphics)
Mime type: image/png
Class: DirectClass
Geometry: 256x256+0+0
Units: Undefined
Type: Bilevel
Base type: Grayscale
Endianess: Undefined
Colorspace: Gray
Depth: 8-bit
Channel depth:
gray: 1-bit
alpha: 8-bithttps://stackoverflow.com/questions/38307757
复制相似问题