Get Image Width and Height using Java
In this example, We will show you about, How to Get Image Width and Height using Java Programming language.
ImageWidthHeight.java
package com.dineshkrish.networking; import java.awt.image.BufferedImage; import java.io.IOException; import java.net.URL; import javax.imageio.ImageIO; /** * * @author Dinesh Krishnan * */ public class ImageWidthHeight { public static void main(String[] args) { String imageUrl = "https://placeholdit.imgix.net/~text?txtsize=56&txt=600%C3%97400&w=600&h=400"; try { // Loading Image URL URL url = new URL(imageUrl); BufferedImage bufferedImage = ImageIO.read(url); System.out.println("Image Height : "+bufferedImage.getHeight()); System.out.println("Image Width : "+bufferedImage.getWidth()); } catch (IOException e) { System.out.println(e.getMessage()); e.printStackTrace(); } } }
Input Image
Output
Image Height : 400
Image Width : 600
References
1. Java ImageIO API
2. Java BufferedImage API
More from my site

Hello, folks, I am a founder of idineshkrishnan.com. I love open source technologies, If you find my tutorials are useful, please consider making donations to these charities.
No responses yet