简体   繁体   English

使用Magick ++将Montage保存到Blob

[英]Save Montage to Blob with Magick++

I have a montage, and I can save it to disk when specified the destination path.However when I try to save it to a Blob it fails. 我有一个蒙太奇,可以在指定目标路径后将其保存到磁盘,但是当我尝试将其保存到Blob时会失败。

Am I missing some settings? 我是否缺少某些设置?

Version: ImageMagick 6.8.2-5 2013-02-05 Q8 版本:ImageMagick 6.8.2-5 2013-02-05 Q8

Machine: Windows 7 x64 机器:Windows 7 x64

EDIT : The exception: 编辑 :例外:

Unhandled Exception: System.Runtime.InteropServices.SEHException: External component has thrown an exception.
   at Magick.throwException(_ExceptionInfo* )
   at Magick.writeImages<class std::_List_iterator<class std::_List_val<class Magick::Image,class std::allocator<class Magick::Image> > > >
   (_List_iterator<std::_List_val<Magick::Image\,std::allocator<Magick::Image> > > first_, _List_iterator<std::_List_val<Magick::Image\,std::allocator<Magick::Image
   > > > last_, Blob* blob_, Boolean adjoin_) in d:\dev\projects\ecs\layers\tools\imagemagicknet\include8\magick++\stl.h:line 2562

The source images 源图像

The Code: 编码:

   void test()
   {
      list<Magick::Image> sourceImageList;
      Magick::Image image;

      image.read("d:\\imtest\\Montage\\1.jpg");
      sourceImageList.push_back(image);
      image.read("d:\\imtest\\Montage\\2.jpg");
      sourceImageList.push_back(image);
      image.read("d:\\imtest\\Montage\\3.jpg");
      sourceImageList.push_back(image);

      Magick::Color color("rgba(0,0,0,0)");

      Montage montageSettings;
      montageSettings.geometry("100x100-0-0");
      montageSettings.shadow(true);
      montageSettings.backgroundColor(color);
      montageSettings.tile( "3x1" );

      list<Magick::Image> montagelist;
      Magick::montageImages( &montagelist, sourceImageList.begin(), sourceImageList.end(), montageSettings);

      // This will give the expected result
      Magick::writeImages(montagelist.begin(), montagelist.end(), "d:\\imtest\\Montage\\out.png");

      Magick::Blob *b = new Magick::Blob();
      // This will throw an exception mentioned above
      Magick::writeImages(montagelist.begin(), montagelist.end(), b);
      Magick::Image imageFromBlob(*b);
      imageFromBlob.write("d:\\imtest\\Montage\\outBlob.png");

   }

You should add try/catch blocks for exceptions so that the exception is caught and can be diagnosed (eg print exception to stderr so that "what" string can be seen). 您应该为异常添加try / catch块,以便捕获异常并对其进行诊断(例如,将打印异常打印到stderr,以便可以看到“ what”字符串)。 It is impossible to diagnose an unhandled exception. 无法诊断未处理的异常。

The proper way to deal with exceptions thrown from Magick++ is detailed at [Magick::Exception]. [Magick :: Exception]中详细介绍了处理从Magick ++引发的异常的正确方法。 1 1

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

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