ImageMagick C ++ API输出16位灰度png?

ImageMagick C ++ API输出16位灰度png?

问题描述:

我通过Magick ++ API链接到ImageMagick。我试图取uint16数据,并将其输出为1024x768单通道16位灰度PNG。我从下面得到的输出是一个RGB8 PNG。

I'm linking to ImageMagick via the Magick++ API. I'm attempting to take uint16 data and output it as a 1024x768 1-channel 16-bit grayscale PNG. The output I get from the following is an RGB8 PNG. The image contents are correct besides the formatting.

gray16_view_t u16view = ...;
uint16_t* data = interleaved_view_get_raw_data(u16view);
size_t length = sizeof(u16) * u16view.width() * u16view.height();
Magick::Blob u16Blob(data, length);
Magick::Geometry size(u16view.width(), u16view.height());
Magick::Image u16MagickImg(u16Blob, size, 16, "GRAY");
u16MagickImg.write("test-16bit.png");

有没有办法更详细地说明输出格式?

Is there any way to specify more about the output format?

有关imagemagick的PNG处理的一些讨论在这里: http://www.imagemagick.org/Usage/formats/#png_formats
他们将PNG8,PNG24和PNG32列为可用格式,但以下部分表示

Some discussion of imagemagick's PNG handling is here: http://www.imagemagick.org/Usage/formats/#png_formats They list PNG8, PNG24, and PNG32 as available formats, but the following section implies that

-define png:bit-depth 16 
-define png:color-type=0 

在命令行上会有所需的输出

on the commandline would have the desired output

    u16MagickImg.quality(00);
    u16MagickImg.defineSet("png:color-type", "0");
    u16MagickImg.defineSet("png:bit-depth", "16");