get Img Height - Java 2D Graphics

Java examples for 2D Graphics:Image

Description

get Img Height

Demo Code


//package com.java2s;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;

import java.io.InputStream;

public class Main {

    public static int getImgHeight(File file) {
        InputStream is = null;//  ww w.j a va  2  s .com
        BufferedImage src = null;
        int ret = -1;
        try {
            is = new FileInputStream(file);
            src = javax.imageio.ImageIO.read(is);
            ret = src.getHeight(null); 
            is.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ret;
    }
}

Related Tutorials