简体   繁体   中英

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.

Am I missing some settings?

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

Machine: 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). It is impossible to diagnose an unhandled exception.

The proper way to deal with exceptions thrown from Magick++ is detailed at [Magick::Exception]. 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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