Error I'm getting with MagickCore but not MagickWand
Posted: 2013-01-24T20:58:01-07:00
I'm learning to use the MagickWand and MagickCore APIs and have a problem with the Core API.
This is a very simple win32 program compiled under cygwin on Windows 7. It has two functions, test_wand() and test_core() which are supposed to read in a bitmap and write the image as a jpg. Here is the function code, essentially lifted from the tutorials:
And here's the result:
The test_wand() function works as expected, reading input_test_WAND.bmp in and writing output_test_WAND.jpg. Hooray.
The test_core() function doesn't work. Not only does it modify the original file (why?):
-rwxr-xr-x 1 pgg None 10006 Jan 24 17:04 input_test_CORE.bmp
-rwxr-xr-x 1 pgg None 10090 Jan 24 17:07 input_test_CORE.bmp
but it doesn't write the output_test_CORE.jpg file.
What error am I making?
Thank you.
This is a very simple win32 program compiled under cygwin on Windows 7. It has two functions, test_wand() and test_core() which are supposed to read in a bitmap and write the image as a jpg. Here is the function code, essentially lifted from the tutorials:
Code: Select all
int test_wand()
{
MagickWand *mw = NULL;
MagickWandGenesis();
mw = NewMagickWand();
if( mw == MagickFalse ) ThrowWandException(mw);
if( MagickReadImage(mw,"input_test_WAND.bmp") == MagickFalse ) ThrowWandException(mw);
if( MagickWriteImage(mw,"output_test_WAND.jpg") == MagickFalse ) ThrowWandException(mw);
if(mw) mw = DestroyMagickWand(mw);
MagickWandTerminus();
return 0;
}
int test_core()
{
Image *image,*imagew;
ImageInfo *read_info;
ImageInfo *write_info;
ExceptionInfo *exception;
// MagickBooleanType status;
MagickCoreGenesis((char *) NULL,MagickFalse);
// Get and Initialize an exception info
exception = AcquireExceptionInfo();
GetExceptionInfo(exception);
// Get and initialize a read_info
read_info=CloneImageInfo(NULL);
CopyMagickString(read_info->filename,"input_test_CORE.bmp",MaxTextExtent);
// Read the image
image = ReadImage(read_info,exception);
imagew = CloneImage(image,0,0,MagickTrue,exception);
// Set up the output info
write_info=CloneImageInfo(read_info);
CopyMagickString(write_info->filename,"output_test_CORE.jpg",MaxTextExtent);
// MagickWriteImage does this so I do it too.
write_info->adjoin=MagickTrue;
// write the image
WriteImage(write_info,imagew);
DestroyImage(image);
DestroyImageInfo(read_info);
DestroyExceptionInfo(exception);
MagickCoreTerminus();
return 0;
}
And here's the result:
Code: Select all
$ ls -l
total 96
drwxr-xr-x+ 1 pgg None 0 Jan 24 16:57 _images
drwxr-xr-x+ 1 pgg None 0 Jan 24 15:27 include
-rwxr-xr-x 1 pgg None 10006 Jan 24 17:04 input_test_CORE.bmp
-rwxr-xr-x 1 pgg None 10006 Jan 24 17:04 input_test_WAND.bmp
-rwxr-xr-x 1 pgg None 935 Jan 22 12:28 Makefile
drwxr-xr-x+ 1 pgg None 0 Jan 24 17:05 obj
drwxr-xr-x+ 1 pgg None 0 Jan 24 15:43 res
drwxr-xr-x+ 1 pgg None 0 Jan 24 17:05 src
-rwxr-xr-x 1 pgg None 10006 Jan 24 16:55 test.bmp
-rwxr-xr-x 1 pgg None 38400 Jan 24 17:05 testprogram.exe
$ ./testprogram.exe
$ ls -l
total 100
drwxr-xr-x+ 1 pgg None 0 Jan 24 16:57 _images
drwxr-xr-x+ 1 pgg None 0 Jan 24 15:27 include
-rwxr-xr-x 1 pgg None 10090 Jan 24 17:07 input_test_CORE.bmp
-rwxr-xr-x 1 pgg None 10006 Jan 24 17:04 input_test_WAND.bmp
-rwxr-xr-x 1 pgg None 935 Jan 22 12:28 Makefile
drwxr-xr-x+ 1 pgg None 0 Jan 24 17:05 obj
-rw-r--r-- 1 pgg None 2420 Jan 24 17:07 output_test_WAND.jpg
drwxr-xr-x+ 1 pgg None 0 Jan 24 15:43 res
drwxr-xr-x+ 1 pgg None 0 Jan 24 17:05 src
-rwxr-xr-x 1 pgg None 10006 Jan 24 16:55 test.bmp
-rwxr-xr-x 1 pgg None 38400 Jan 24 17:05 testprogram.exe
The test_core() function doesn't work. Not only does it modify the original file (why?):
-rwxr-xr-x 1 pgg None 10006 Jan 24 17:04 input_test_CORE.bmp
-rwxr-xr-x 1 pgg None 10090 Jan 24 17:07 input_test_CORE.bmp
but it doesn't write the output_test_CORE.jpg file.
What error am I making?
Thank you.