Page 1 of 1

Read function of ImageMagick throws Access violation error.

Posted: 2012-06-11T02:54:24-07:00
by mbatra
Hi,

I am using ImageMagick (Magick++) library. I want to use the features of Magick++ in VC++ application. I have written the below code to read a file from the memory.

Image image;
image.read("D:\\smile.gif");
image.rotate(145);
image.write( "red_pixel.gif" );

When I compile the above code, it throws "0xC0000005: Access violation writing location 0xcf305b0c." Error. Can anyone have any idea why its throwing this error.
I want to use Magick++ features in VC++ applications.


Regards,
Mbatra

Re: Read function of ImageMagick throws Access violation err

Posted: 2012-07-14T16:00:43-07:00
by july-n.n
Oh, I have the same problem. I'm not along. Somebody help us, please.

Thanks a lot.

Re: Read function of ImageMagick throws Access violation err

Posted: 2012-07-16T04:23:25-07:00
by mike
From the Magick++ C++ API documentation:
Note, under Windows (and possibly the Mac) it may be necessary to initialize the ImageMagick library prior to using the Magick++ library. This initialization is performed by passing the path to the ImageMagick DLLs (assumed to be in the same directory as your program) to the InitializeMagick() function call. This is commonly performed by providing the path to your program (argv[0]) as shown in the following example:

int main( int argc, char ** argv) {
InitializeMagick(*argv);
...
This initialization step is not required under Unix, Linux, Cygwin, or any other operating environment that supports the notion of installing ImageMagick in a known location.
edit2: Also have a look into the Magick::Image Class documentation. The example you need is there, but I have found it only after I've posted the code below which is based on those examples.

edit: I'm including part of my code that is tested and works on my 32bit Windows 7 machine

Disclaimer: I don't usually do C++ nor Win32 programming

Code: Select all

#include "stdafx.h"
#include <string>
#include <Magick++.h>

using namespace Magick;

int main(int argc, char** argv)
{
	InitializeMagick(*argv);

	try
	{ 
		Image inputImage;
		std::string inputFileName;
		if(argc > 1){
			inputFileName = argv[1];
			inputImage.read(inputFileName);
			std::printf("Reading file \"%s\"", inputFileName.c_str());
		}else{
			std::printf("Usage:\n%s %s", argv[0], "input-file");
			exit(1);
		}

		std::printf("Image read OK\n");

		std::printf("Making copy of the original into alpha\n");
		Image alpha = inputImage;

		std::printf("Changing levels on Alpha channel (0,1,9.99)\n");
		alpha.levelChannel(MatteChannel, 0, 1, 9.99);
		
		std::printf("Modulating\n");
		alpha.modulate(0.15, 1.0, 1.0);

		std::printf("Copying alpha back to the original picture\n");
		inputImage.composite(alpha, 0, 0, MagickCore::CopyOpacityCompositeOp);

		std::printf("Leveling the image\n");
		inputImage.level(0, 230, 1.0);

		std::string outputFileName;
		outputFileName.append(std::string(inputFileName)).append("-2.png");

		inputImage.write(outputFileName);
		std::printf("Image write \" %s \"\n", outputFileName.c_str());
	} catch( Exception &error_ ) 
	{ 
		std::printf("Caught exception: %s\n", error_.what()); 
		return 1; 
	} 
	return 0;
}

Re: Read function of ImageMagick throws Access violation err

Posted: 2012-11-14T02:15:15-07:00
by mbatra
Hi,

I have solved the problem. Now my code is working for windows 7 as well as for WinXP.


Regards,
mbatra

Re: Read function of ImageMagick throws Access violation err

Posted: 2013-01-22T01:30:44-07:00
by mbatra
ykfdf wrote:I have the same problem

_________________
WoW gold|Diablo 3 Gold|Aion Kinah kaufen|Diablo 3 Gold kaufen

Hi,

Follow the below given link ...
http://flightschool.acylt.com/devnotes/ ... d-vs-2010/

Also try to re-build the code in "Release" mode. Same code will be working fine.




Regards,
Mbatra