本文實例講述了java獲取圖片像素的方法。分享給大家供大家參考,具體如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
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 + "." ); } } |
希望本文所述對大家Java程序設計有所幫助。