小任班长的博客 - java图片宽高
type: channel
link: https://cnxiaocheng.top/tag/java图片宽高/
items: java获取上传图片宽高 验证图片尺寸

java获取上传图片宽高 验证图片尺寸
type: item
date: 2019-11-28T09:00:00+08:00
description: java判断上次图片的尺寸，将得到的文件对象转成流，使用ImageIO读取获取宽高属性BufferedImage curImg = ImageIO.read(file.getInputStream()); int picWidth = curImg.getWidth();//获取宽 int picHeight = curImg.getHeight();//获取高 int standWidth = Integer.parseInt(width); int standHeight = Integer.parseInt(height); //给客户预留一些误差 if(Math.abs(standWidth-picWidth) >5 || Math.abs(standHeight-picHeight) >5){ result.setCode(-2); return result; }