日期:2014-05-16  浏览次数:20376 次

java jsp servlet fileupload上传图片时获取上传图片尺寸(宽高)的代码

java jsp servlet fileupload上传图片时获取上传图片尺寸(宽高)的代码

?

DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);

List items = upload.parseRequest(request);
Iterator iter = items.iterator();
while (iter.hasNext()) {
	if (!item.isFormField()) {
		BufferedImage img = javax.imageio.ImageIO.read(item.getInputStream());
    	img.getWidth()//获取宽
    	img.getHeight()//获取高
	}
}
?