Problems with image.read

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
Hyde
Posts: 3
Joined: 2018-01-10T08:07:41-07:00
Authentication code: 1152

Problems with image.read

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problems with image.read

Post 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.
snibgo's IM pages: im.snibgo.com
Hyde
Posts: 3
Joined: 2018-01-10T08:07:41-07:00
Authentication code: 1152

Re: Problems with image.read

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problems with image.read

Post 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?
snibgo's IM pages: im.snibgo.com
Hyde
Posts: 3
Joined: 2018-01-10T08:07:41-07:00
Authentication code: 1152

Re: Problems with image.read

Post 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
Post Reply