Check Image Resolution in Java
At first we might tempted to use any 3rd party software for checking image resolution using JAVA. But JAVA has already provided an set of APIs that allows Image Manipulations. This APIs is called Java Advanced Imaging also called JAI. In this article we will learn how we can check the image resolution using Java Advanced Imaging APIs.
Java Advanced Imaging:
The APIs can be downloaded from Download Java Advanced Imaging
Now lets jump into the code part as we all are interested in that:
Check Remote Image Resolution in JAVA
import java.net.MalformedURLException; import java.net.URL; import javax.media.jai.JAI; import javax.media.jai.PlanarImage; class CheckResolution { String imageURL = "http://www.google.co.in/intl/en_com/images/logo_plain.png"; public static void main(String[] args) throws MalformedURLException { CheckResolution cr = new CheckResolution(); URL imageurl = new URL(cr.imageURL); PlanarImage pi = JAI.create("url", imageurl); int imagewidth = pi.getWidth(); int imageheight = pi.getHeight(); System.out.println("Image Width:" + imagewidth + " --- Image Height:" + imageheight); } }
Output:
Image Width:276 — Image Height:110
Check Local Image Resolution in JAVA
import javax.media.jai.JAI; import javax.media.jai.PlanarImage; class CheckResolution { String imageURL = "C:\\logo_plain.png"; public static void main(String[] args) { CheckResolution cr = new CheckResolution(); PlanarImage pi = JAI.create("fileload", cr.imageURL); int imagewidth = pi.getWidth(); int imageheight = pi.getHeight(); System.out.println("Image Width:" + imagewidth + " --- Image Height:" + imageheight); } }
Output:
Image Width:276 — Image Height:110
Custom Search















