---
title: "java获取图片长度和宽度"
author: "cs_man"
date: "2010-04-25T23:33:22Z"
tags: []
categories: ["编程语言"]
slug: "java"
draft: false
lastmod: "2010-04-25T23:36:29Z"
id: 652918
url: "https://cs-man.iteye.com/blog/652918"
---

```java
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);
	}

}

```