java如何判断图片的长度和宽度呢?

杨采妮 Java经验 发布时间:2022-05-25 22:29:18 阅读数:1974 1
下文笔者讲述使用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;
}
版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

本文链接: https://www.Java265.com/JavaJingYan/202205/16534890043512.html

最近发表

热门文章

好文推荐

Java265.com

https://www.java265.com

站长统计|粤ICP备14097017号-3

Powered By Java265.com信息维护小组

使用手机扫描二维码

关注我们看更多资讯

java爱好者