java如何判断图片的长度和宽度呢?
下文笔者讲述使用java代码获取图片长度和宽度的方法分享,如下所示
实现思路:
1.使用ImageIO.read()方法读取图片为一个BufferedImage对象
2.使用BufferedImage对象的getWidth和getHeight()方法
即可获取其长度和宽度,然后对其进行判断
例:
/**
* 图片长度和宽度判断方法
*
* @param imgPath 图片长度和宽度判断
* @return
* @throws IOException
*/
public static boolean judgeImgPixel(String imgPath) throws IOException {
BufferedImage bi = ImageIO.read(new FileInputStream(imgPath));
int width = bi.getWidth();
int height = bi.getHeight();
if (width < 128 || height < 128 || width > 4096 || height > 4096) {
return false;
}
return true;
}
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


