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()//获取高
	}
}
 

你可能感兴趣的:(java编程,javaweb)