"Magick++::readImages" 当我调用它来解码 Blob 对象中的 png 图像时抛出警告

"Magick++::readImages" throw a warning when I invoke it to decode a png image inside a Blob object

我用Magick++处理图片,下面的代码抛出警告:"Magick: iCCP: known incorrect sRGB profile () reported by coders/png.c:1105 (PNGWarningHandler)"

......
string img;
//assign image to this string(img)
std::list<Image> m_images;
......
Blob src_blob(image.data(), image.length());
readImages(&m_images, src_blob);//in this function throw a warning exception
if (!m_images.empty()) {
    Image image = *(m_images.begin());
}
......

但是如果我这样构建图像:

Blob src_blob(image.data(), image.length());
Image image(src_blob);

代码会起作用,不会抛出异常

这张图片的名称:

$identify case1.png
case1.png PNG 800x800 800x800+0+0 8-bit sRGB 807280B 0.000u 0:00.004

(我必须使用 readImages 因为我可能会处理 gif 图片)

尝试以下...

std::list<Image> m_images;
// ...
ReadOptions opts;
opts.quiet(true);
Blob src_blob(image.data(), image.length());
readImages(&m_images, src_blob, opts);

ReadOptions.quiet 设置为 true 将在解码期间抑制任何警告。

// From `Magick::throwException` method.
if ((quiet_) && (severity < MagickCore::ErrorException))
{
  delete nestedException;
  return;
}

But if I construct Image like this:

Blob src_blob(image.data(), image.length());
Image image(src_blob);

the codes will work and no throw exception

这是因为constructor-helper方法为了方便临时设置了quiet

// From Image.cpp
Magick::Image::Image(const Blob &blob_)
  : _imgRef(new ImageRef)
{
  try
  {
    // Initialize, Allocate and Read images
    quiet(true);
    read(blob_);
    quiet(false);
  }
  catch (const Error&)
  {
    // Release resources
    delete _imgRef;
    throw;
  }
}