标签 java验证尺寸 下的文章

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;
}
免责声明
本博客部分内容来自于互联网,不代表作者的观点和立场,如若侵犯到您的权益,请联系[email protected]。我们会在24小时内进行删除。