Output of Convert command to Blob

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
Tony
Posts: 3
Joined: 2012-05-25T12:56:49-07:00
Authentication code: 13

Output of Convert command to Blob

Post by Tony »

I am using the following code in a Magic++ application...

Code: Select all

 MagickBooleanType status = ConvertImageCommand(image_info, args_count, args, NULL, exception);
Is it possible for the ConvertImageCommand to write its output to a Blob or use some other 'in memory' technique?
I am trying to avoid writing the output to disk via the command and then re-reading the output file into the application.
There are vague reference in some other posts concerning blobs, file descriptors, stdin/stdout and streams but I have been unable to locate a specific technique with examples.

Thanks.
spongemonkey
Posts: 20
Joined: 2012-10-08T13:42:11-07:00
Authentication code: 67789

Re: Output of Convert command to Blob

Post by spongemonkey »

This sort of code isn't how to use the Magick++ API.

You'd do something like

Code: Select all

#include <Magick++>

using namespace Magick;
using namespace std;

...

// open an image
Image image("some_image.jpg");

// perhaps do something to the image
image.resize(Geometry(500,500));

// will hold the image data in memory rather than writing it to a file
Blob blob;

// write the resized image data to the blob in png format
image.write(&blob,"png");

// perhaps then we'll write it to disk
ofstream outFile;
	
outFile.open("was_once_held_in_memory_by_IM.png", ios::out | ios::binary);

// blob.data() returns a void* with the actual data, blob.length() tells you how much data is there
outFile.write((char*)blob.data(),blob.length());
outFile.close();
If you give more info about what you want to do I might be able to help more
Post Reply