Checking Image Resolution from Java Applications
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
Popular Articles:
- Modifying / Editing XML Document in JAVA
- Logging User Session details using Apache log4j
- Performing Text To Speech (TTS) conversion on linux using Java
- Log4J Logging Inside Eclipse Console
- JSP – Create Custom Tags
- Singleton Design Pattern in Java
- Java Plugin detection using JavaScript
- UTF-8 Encoding Email Content using Java
- Invoking Class Methods using Reflection in Java
- Reading New Emails from Java Applications


































