JAVA获取图片宽高_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > JAVA获取图片宽高

JAVA获取图片宽高

 2013/8/8 13:08:22  dreamoftch  程序员俱乐部  我要评论(0)
  • 摘要:packagetest;importjava.awt.image.BufferedImage;importjava.io.File;importjava.io.FileInputStream;importjava.io.FileNotFoundException;importjava.io.IOException;importjava.util.Iterator;importjavax.imageio.ImageIO;importjavax.imageio.ImageReader
  • 标签:图片 Java
class="java" name="code">package test;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;

import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;

public class bbb {
	
	public static void main(String[] args) throws FileNotFoundException, IOException {
		try {
		   //方法1:
		   File file = new File("d:/ant_logo_large.gif");
		   Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("gif");
		   ImageReader reader = (ImageReader)readers.next();
		   ImageInputStream iis = ImageIO.createImageInputStream(file);
		   reader.setInput(iis, true);
		   System.out.println("width:"+reader.getWidth(0));
		   System.out.println("height:"+reader.getHeight(0));
		   //方法2:
		   File picture = new File("d:/ant_logo_large.gif");
	       BufferedImage sourceImg =ImageIO.read(new FileInputStream(picture)); 
	       System.out.println(sourceImg.getWidth());
	       System.out.println(sourceImg.getHeight());
		} catch (IOException e) {
		   e.printStackTrace();
		  }
	}
}

?链接:http://immortal2512.iteye.com/blog/406744

发表评论
用户名: 匿名