简体   繁体   English

Magick ++-减少灰度图像的位深度

[英]Magick++ - reduce bit-depth of grayscale image

I'm trying to reduce the channel-bit-depth of PNGs from 8 to 4 using Magick++. 我正在尝试使用Magick ++将PNG的通道位深度从8减少到4。 I'm using the following code to do this: 我正在使用以下代码执行此操作:

Image * img = new Image("./image8.png");
img->channelDepth(ChannelType::AllChannels,4);
img->write("./image4.png");

For color-images, this works great. 对于彩色图像,这很好用。 But for grayscale images, ImageMagick does something strange. 但是对于灰度图像,ImageMagick做一些奇怪的事情。 It squeezes the whole content into the left half of the image and displays random pixels in the right half. 它将全部内容压缩到图像的左半部分,并在右半部分显示随机像素。

For example this baboon here: 例如,这里的狒狒: 在此处输入图片说明

turns into this with the code above: 上面的代码变成这样: 在此处输入图片说明

Does anybody have an explanation for this behavior and/or an idea how I can solve this? 有人对此行为有一个解释和/或一个想法我该如何解决吗?

Or is this maybe even a bug of image magick? 还是这甚至是图像魔术的错误?

Looks like a bug in your version of ImageMagick. 看起来像您的ImageMagick版本中的错误。 The current version (6.9.2-8) doesn't exhibit the bug when running it from the commandline: "convert 5koQD.png -depth 4 depth4.png" 从命令行运行时,当前版本(6.9.2-8)不会出现该错误:“ convert 5koQD.png -depth 4 depth4.png”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM