image.read() failing

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
PBert
Posts: 11
Joined: 2014-03-06T04:34:54-07:00
Authentication code: 6789

image.read() failing

Post by PBert »

Hi Folks,

when trying to init an image by reading from a file location, my program crashes. Here's what I've gone in circles around:

Code: Select all

InitializeMagick("...");    // tried a few locations from the program location, to null
Image image;
image.read("...");    // crash
But if I init an image using:

Code: Select all

Image image(Geometry(100,100),Color(255,200,0,255)));    // coloured orange for testing
all is fine, including running the image through routines (e.g. contrast). But I cannot read, nor write (image.write("..") does nothing either, though it doesn't crash).

What might be causing this, or where might I be going wrong?

I'm using a static build (6.8.5 I think), testing on win7 (program is intended for win and mac). Not sure what else I could add that might help. Let me know if more is needed.

Cheers,

PB.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: image.read() failing

Post by snibgo »

What is your development environment? I'll guess it is MSVC and you are in debug mode. See this recent thread: viewtopic.php?f=2&t=26109

If that doesn't help: do the demo programs compile and run?
snibgo's IM pages: im.snibgo.com
PBert
Posts: 11
Joined: 2014-03-06T04:34:54-07:00
Authentication code: 6789

Re: image.read() failing

Post by PBert »

Hi snibgo,

development is being done in VS Exp. 2010, and the crashes are happening in release builds. I must confess, generally speaking, I don't do debug builds as I test most things manually myself by (e.g.) printing variable values etc.

For notes' sake, the build ends up as a dll (albeit with another extension) and is a plugin that runs under the wing of another major piece of software. The plugin runs fine, until .read() is called. I should have mentioned also that the IM namespace and routines are buing called inside namespace brackets like the following:

Code: Select all

void MyFunction(void)
{
    using namespace MyMagic
    {
        InitImageMagic..
        Image image;
    }
}
Is this likely to make any difference?

Most (90%+) of the demos build. Of the ones that do build, when running the .exe a window is opened, but it disappears very quickly - so I'm not sure if they're doing what they're meant to or not.

PB.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: image.read() failing

Post by snibgo »

Sorry, I have forgotten anything I ever knew about Visual Studio. When you have built the demo programs, you should be able to run them from the command line. They should read and write image files successfully.
snibgo's IM pages: im.snibgo.com
PBert
Posts: 11
Joined: 2014-03-06T04:34:54-07:00
Authentication code: 6789

Re: image.read() failing

Post by PBert »

That's no worries, thanks for having a go - I'll do a bit more testing with the demos and the command line at some stage to see if anything further can come out of them.

In the meantime, I may have found a workaround that, while not the most efficient way, might do enough to at least continue with other areas of development until another solution/someone else comes along to chip in!

Cheers,

PBert.
PBert
Posts: 11
Joined: 2014-03-06T04:34:54-07:00
Authentication code: 6789

Re: image.read() failing

Post by PBert »

Hi folks,

I've 'worked out' what the problem is here. See examples:

Code: Select all

// this fails
Image Img1;
Img1.read("C:\test.png");

// this works
Image Img1;
Img1.read("C:/test.png");

// note the difference is the folder characters ("\" and "/")
Would be happy to hear from anyone who might be able to explain the above, if anything just for knowledge's sake. Otherwise, the change seems to of worked.

Cheers,

PBert.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: image.read() failing

Post by snibgo »

Have you built your program plus libraries as a Unix program or a Windows program? Unix programs want "/", and Windows programs want "\".

I haven't figured out this stuff myself, but you might discover something if you insert this in your code:

Code: Select all

#if defined(MAGICKCORE_WINDOWS_SUPPORT)
  printf ("MAGICKCORE_WINDOWS_SUPPORT defined\n");
#endif

#if defined(WIN32)
  printf ("WIN32 defined\n");
#endif

#if defined(WIN64)
  printf ("WIN64 defined\n");
#endif
snibgo's IM pages: im.snibgo.com
Post Reply