Search code examples
javaimageimagemagickjmagick

magick.MagickException: Unable to retrieve handle


I am trying to use JMagick in my app for last one week but sm still unsuccesfull. I installed JMagick 6.4.0 and ImageMagick 6.4.0 from source itself using default installation directories. I can see shared libraries in /usr/local/lib.

Now I try to run following program with option -Djava.library.path=/usr/local/lib.

public class JMagickTest {
    public static void main(String[] args) {
        try {
            System.setProperty("jmagick.systemclassloader", "false");
            System.out.println(System.getProperty("java.library.path"));
            ImageInfo info = new ImageInfo("/home/blue_bg.jpg");
            MagickImage image = new MagickImage(info);
            System.out.println(image.getBackgroundColor());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

It gives following error.

/usr/local/lib
magick.MagickException: Unable to retrieve handle
        at magick.MagickImage.getBackgroundColor(Native Method)
        at JMagickTest.main(JMagickTest.java:19)

Could any one please help me here. Also Could some please suggest proper way to uninstall ImageMagick from system.

Thanks in advance
Jitendra


Solution

  • Finally I found out the error.

    I think, Unable to retrieve handle is a very generic error which may occur due to variety of reasons. One could be multiple installations of Imagemagick.

    Error in my case was, delegate library for JPEG format was not installed. so I followed instructions on http://blog.ericlamb.net/2008/11/fix-for-convert-no-decode-delegate-for-this-image-format/ to first install this library then re install imagemagick. It solved the problem.