ITeye博客

java获取图片长度和宽度

cs_man · 2010-04-25 23:33 · Java · 编程语言 · Markdown

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class Test {

	public static void main(String[] args) {
		File picFile = new File("D:\\1.gif"); // 图片文件路径
		BufferedImage image = null;
		try {
			image = ImageIO.read(picFile);
		} catch (IOException e) {
			e.printStackTrace();
		}
		int width = image.getWidth();// 图片宽度
		int height = image.getHeight();// 图片高度
		System.out.println("width=" + width);
		System.out.println("height=" + height);
	}

}

评论(2)

  1. #2 楼 · cs_man · 2011-09-07 19:52

    lost-java writes:

    刚好用到,thank you !

    不客气!哈哈

  2. #1 楼 · lost-java · 2011-07-11 12:46

    刚好用到,thank you !

评论功能维护中,当前仅展示历史评论。