image.read() throws exception and fails. But works when creating constructor?

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
josephaaroncampbell
Posts: 40
Joined: 2015-07-14T19:18:45-07:00
Authentication code: 1151
Location: Chicago, IL

image.read() throws exception and fails. But works when creating constructor?

Post by josephaaroncampbell »

Hello,

I am using version:

Version: ImageMagick 7.0.3-5 Q16 x64 2016-11-08 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Visual C++: 180040629
Features: Cipher DPC HDRI Modules OpenMP
Delegates (built-in): bzlib cairo flif freetype jng jp2 jpeg lcms lqr openexr pangocairo png ps rsvg tiff webp xml zlib

Windows 10 64bit.

I also installed the headers for Magic++, MagickCore, and MagickWand.

I am usinig QT Creator as an IDE. I can link and compile the Magick++ library and headers.

My Code:

Code: Select all

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

using namespace std;
using namespace Magick;

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

    cout << *argv << endl;

    InitializeMagick(*argv);

    // Construct the image object. Seperating image construction from the
    // the read operation ensures that a failure to read the image file
    // doesn't render the image object useless.
    Image image;
    try {
      // Read a file into image object
      image.read( "target.tif" );


      // Write the image to a file
      image.write( "x6.jpg" );
    }
    catch( Exception &error_ )
      {
        cout << "Caught exception: " << error_.what() << endl;
        return 1;
      }
    return 0;
}
This does not work. I get the following exception in the command prompt for the program:
Caught exception: magickTest.exe: Incompatible type for "RichTIFFIPTC"; tag ignored. `TIFFFetchNormalTag' @ warning/tiff.c/TIFFWarnings/905
Press <RETURN> to close this window...
HOWEVER. If I switch the .read image to JPEG or some other format it works. IT only fails with TIFF.

ALSO, I can use .tiff images. If I move the action of reading the .tiff image into the Constructor it works with no problems.

like so:

Code: Select all

Image image("target.tif");
    try {

      // Write the image to a file
      image.write( "x8.gif" );
    }
    catch( Exception &error_ )
      {
        cout << "Caught exception: " << error_.what() << endl;
        return 1;
      }
    return 0;
So, is it that the 'catch' is returning the exception and preventing the write function from working?

Also, as this may be important, I get a ton of C4251 warnings when building the program. Probably over 50 or so:
C:\Program Files\ImageMagick-7.0.3-Q16-HDRI\include\Magick++\Drawable.h:2928: warning: C4251: 'Magick::PathLinetoRel::_coordinates': class 'std::vector<Magick::Coordinate,std::allocator<_Ty>>' needs to have dll-interface to be used by clients of class 'Magick::PathLinetoRel'
with
[
_Ty=Magick::Coordinate

C:\Program Files\ImageMagick-7.0.3-Q16-HDRI\include\Magick++\Exception.h:23: warning: C4275: non dll-interface class 'std::exception' used as base for dll-interface class 'Magick::Exception'

C:\Program Files\ImageMagick-7.0.3-Q16-HDRI\include\Magick++\Exception.h:56: warning: C4251: 'Magick::Exception::_what': class 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' needs to have dll-interface to be used by clients of class 'Magick::Exception'
]

I also get this exception error:
:-1: warning: Exception at 0x7ffbb5c47788, code: 0xe06d7363: C++ exception, flags=0x1 (execution cannot be continued) (first chance)

They all seem to be ' Needs to have dll-interface to be used by clients of class 'Magick::Exception'. So maybe I do not have something set up correctly here.

Any help will be much appreciated as I am obviously new to this.

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

Re: image.read() throws exception and fails. But works when creating constructor?

Post by snibgo »

Caught exception: magickTest.exe: Incompatible type for "RichTIFFIPTC"; tag ignored. `TIFFFetchNormalTag' @ warning/tiff.c/TIFFWarnings/905
Like the other thread today viewtopic.php?f=1&t=25721 this is merely a warning, not an error.
snibgo's IM pages: im.snibgo.com
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: image.read() throws exception and fails. But works when creating constructor?

Post by dlemstra »

You can do the following to ignore warnings (same as -quiet on the command line):

Code: Select all

image.quiet(true);
This is done in the constructor automatically:

Code: Select all

Magick::Image::Image(const std::string &imageSpec_)
  : _imgRef(new ImageRef)
{
  try
  {
    // Initialize, Allocate and Read images
    quiet(true);
    read(imageSpec_);
    quiet(false);
  }
  catch(const Error&)
  {
    // Release resources
    delete _imgRef;
    throw;
  }
}
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
Post Reply