The run time error of ImageToFile in MagickCore

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
shiengchyi
Posts: 4
Joined: 2011-04-28T00:17:33-07:00
Authentication code: 8675308

The run time error of ImageToFile in MagickCore

Post by shiengchyi »

I use the ConstituteImage function to generate a GRAY Level image, then use the ImageToFile function to save the image file in JPEG format.
The version of ImageMagick is 6.5.4-8 2009-10-24 Q16 OpenMP.
Here is the code.

ExceptionInfo *exception;
exception = AcquireExceptionInfo();

Image *img;
img = ConstituteImage(height, width, "I", CharPixel, imgBlobBuffer, exception); //imgBlobBuffer is an Unsigned Char array, and one byte per pixel
ImageToFile(img, Path, exception); //Path is file path like this "./test.jpeg"

I get a run time error at ImageToFile function:
magick/blob.c:1523: ImageToFile: Assertion `image->blob->type != UndefinedStream' failed. Aborted

Does anybody could tell me what wrong is it?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: The run time error of ImageToFile in MagickCore

Post by magick »

Use WriteImage() rather than ImageToFile(). ImageToFile() reads bytes from disk and writes them to the specified file whereas WriteImage() writes the image pixels to disk in the format you specify.
shiengchyi
Posts: 4
Joined: 2011-04-28T00:17:33-07:00
Authentication code: 8675308

Re: The run time error of ImageToFile in MagickCore

Post by shiengchyi »

Yeah~ It is wording now!! Thank you very much~!!
Post Reply