---
title: "JAVA获得图片像素"
author: "java110eye"
date: "2011-08-03T14:33:36Z"
tags: []
categories: ["编程语言"]
slug: "java"
draft: false
lastmod: "2011-08-03T14:33:36Z"
id: 1139076
url: "https://java110eye.iteye.com/blog/1139076"
---

```
package cn.net.comsys.sso;

import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.*;

public class Test {
	public static void main(String args[]) {

		File file = new File("a.bmp");
		BufferedImage bi = null;
		try {
			bi = ImageIO.read(file);
		} catch (Exception e) {
			e.printStackTrace();
		}

		int width = bi.getWidth(); // 像素
		int height = bi.getHeight(); // 像素
		System.out.println("width=" + width + ",height=" + height + ".");

	}

}
```