1

Using Jmagick Java APIs, How do I get the image information such as:

Codec, Color scheme, Color depth, Width, Height, Resize directive, Image Size etc.

I tried executing the below code, but it did not give any useful details.

public static void main(String[] args) throws Exception {

   String baseDir = System.getProperty("user.dir");
   String pngFile = baseDir + File.separator + "input" + File.separator + "image.jpg";

   DisplayImageMetaData metaData = new DisplayImageMetaData();

   // Input BMP file
   String inputfileName = pngFile;

   // Get BMP file into ImageInfo object
   ImageInfo info = new ImageInfo(inputfileName); 
   DisplayImageMetaData.displayImageInfo(info);
}

It give me following output, which is different.

Info PreviewType is 0(UndefinedPreview)
Info Monochrome is 0
Info Colorspace is 0(UndefinedColorspace)
Info Resolution units is 0
Info Compression is 0(UndefinedCompression)
Info Density is null
Info magick is 
Info filename is /home/host1/javaWs/JMagick/input/image.jpg
Andrea
  • 11,801
  • 17
  • 65
  • 72
AnilJ
  • 1,951
  • 2
  • 33
  • 60
  • Hello Folks, is that something I am missing in my code? This is an important piece of information I am looking for to decide if my device is capable of using the image, and transcode the image accordingly. – AnilJ Sep 27 '13 at 17:17

1 Answers1

1

Instead of using DisplayImageMetaData try the MagickImage class.

/** Typical scaling implementation using JMagick **/
ImageInfo origInfo = new ImageInfo("C:/Users/windows 7/Pictures/Desert.jpg"); //load image info
MagickImage image = new MagickImage(origInfo); //load image
System.out.println(image.getDimension() + " " + image.getColorspace() + " " + image.getFileName() + " " + image.getXResolution() + " " + image.getYResolution());

The output for my test image is

java.awt.Dimension[width=1024,height=768] 1 C:/Users/windows 7/Pictures/Desert.jpg 72.0 72.0

A lot of image information is available within the MagickImage class (JMagick documentation).

Neel Borooah
  • 91
  • 1
  • 1
  • 11