Page 1 of 1

Problems with image.read

Posted: 2018-01-10T08:43:06-07:00
by Hyde
Hi,

I am trying to create a software that converts a pdf into a bmp file. I am using visual studio 2017 to create a clr/c++ project.
The version of magick++ is ImageMagick-7.0.7-21-Q16 for (x86).

I have added and linked all the .h, .lib and .dll files, the code gets compiled without problems, but when I try to read a file it gives an exception (System.Runtime.InteropServices.SEHException: 'external component has thrown an exception').

This is the piece of code (is compiled under release(x86)):

msclr::interop::marshal_context context;
Magick::Image myImage;

//Choose the pdf
myImage.read(context.marshal_as<std::string>(openFileDialog1->FileName)); //Exception called here
//Write a bmp
myImage.write("file.bmp");

I have run the same code under release(x64), used the same library (but for x64), added and linked the .h and .lib files (it runs without the .dll files, instead of the x86 version, that without them would call a 0xc000007b error).

Sorry for my bad english
Best regards

Re: Problems with image.read

Posted: 2018-01-10T11:53:19-07:00
by snibgo
The problem could be almost anything. Have you initialized ImageMagick? What is the value returned by openFileDialog1->FileName?

I suggest you create a minimal non-interactive program that shows the problem.

Re: Problems with image.read

Posted: 2018-01-11T02:00:47-07:00
by Hyde
I have tried to initialize magick, but I still got problems. The value returned by openFileDialog1->FileName is a System String, and it is converted into a std string.

I have created a program to show where is the problem (as you suggested). This is the code:

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

using namespace System;

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

Magick::Image myImage;
try
{
myImage.read("filePDF.pdf");
}
catch (const std::exception& error)
{
if (error.what()==NULL)
myImage.write("fileBMP.bmp");
else
std::cout << error.what() << "\r\n";
}

system("pause");
}

It gives to me the following output-> RegistryKeyLookupFailed `CoderModulesPath' @ error/module.c/GetMagickModulePath/665

Re: Problems with image.read

Posted: 2018-01-11T02:46:57-07:00
by snibgo
Does IM work at the command line? For example:

Code: Select all

magick filePDF.pdf fileBMP.bmp
magick rose: r.png
magick r.png r2.png
magick rose: r.jpg
If those don't work, then IM hasn't been installed successfully.

If those do work, then are you moving your compiled binary to the same directory as magick.exe?

Re: Problems with image.read

Posted: 2018-01-15T00:35:56-07:00
by Hyde
Sry for answer so late.
It doesn't work on command line, I have reinstalled the package and removed the version for x64. At the moment works.
I guess the reason of the problem was a conflict of paths.
Thanks for your attention and help

Best regards