Discussion:
Crash on MagickWriteImageFile (on Windows)
Andrea Parenti
2011-11-01 17:09:53 UTC
Permalink
Dear all,

I wonder how to use MagickWriteImageFile (on Windows 7, 64 bits). Is there any
example? I would think I am doing things right but I get a crash when calling
the above mentioned function. The following is my main.cpp:

#include <iostream>
#include <wand/MagickWand.h>

using namespace std;

int main() {
const int x_size=2560, y_size=2160, img_size=x_size*y_size;
MagickBooleanType status;
MagickWand *wand = NULL;

MagickWandGenesis();
wand = NewMagickWand();

unsigned short *pixels;
pixels = new unsigned short[img_size];

for (int j=0; j<img_size; ++j) {
pixels[j] = unsigned short(j*65535./img_size);
}

if (MagickConstituteImage(wand, x_size, y_size, "I", ShortPixel, pixels) ==
MagickFalse)
cout << "Cannot constitute image" << endl;
if (MagickSetImageFormat(wand, "TIFF") == MagickFalse)
cout << "Cannot set format" << endl;

// This works fine
if (MagickWriteImages(wand, "test.tif", MagickTrue) == MagickFalse)
cout << "Cannot write test.tif" << endl;

// This does not work! Crash on MagickWriteImageFile
FILE *file;
file = fopen("test2.tif", "wb");
if (MagickWriteImageFile(wand, file) == MagickFalse) // CRASH here!
cout << "Cannnot write test2.tif" << endl;
fclose(file);

wand = DestroyMagickWand(wand);
MagickWandTerminus();
delete pixels;

return 0;
}


Some more info: I have installed the ImageMagick library using
ImageMagick-6.7.3-3-Q16-windows-x64-dll.exe, and I compile the main.cpp with
nmake (from VC) and the following Makefile:

all: main

clean:
del *.exe *.obj

main: main.obj
link /OUT:"main.exe" /LIBPATH:"C:\Program Files\ImageMagick-6.7.3-Q16\lib"
CORE_RL_wand_.lib main.obj

main.obj: main.cpp
cl /I "C:\Program Files\ImageMagick-6.7.3-Q16\include" /EHsc /c main.cpp /D
WINDOWSXX


Thank you very much!

Andrea Parenti

Loading...