Magick++ doesn't seem to write multi-image Images to a single blob. Regardless if the image has multiple sub-images, it always calls ImageToBlob, when it appears it should be calling ImagesToBlob instead, if needed. I'm guessing this applies to multi-page TIFFs, PDFs, and others as well?
Anyhoo, here's my wrapper around the Write method, perhaps something like this could be integrated into Magick++ to save someone else the headache later on:
Code: Select all
#include <Magick++.h>
#include <magick/blob.h> // ImagesToBlob
// writes a magick image to the target blob
void write_magick_img( Magick::Image& img, Magick::Blob& target )
{
if ( img.constImage()->next == NULL ) // has multiple images?
{
img.write( &target ); // forward to regular write method
}
else // Magick++ doesn't write multiple image to blob, need to use blob.c / ImagesToBlob
{
img.adjoin( true ); // manually set adjoin param, not sure if this is needed
size_t sz = 0;
unsigned char* data = ImagesToBlob( img.constImageInfo(), img.image(), &sz, &img.image()->exception );
target.updateNoCopy( data, sz, Magick::Blob::MallocAllocator ); // Magick::Blob takes ownership here
}
} // write_magick_img