java-如何获取本地图片的宽度和高度

虽然真的很简单,但是为了记录实习过程中用代码处理的那些奇奇怪怪的事情,还是记录下来:
这个功能是在我检查图片的时候为了减少工作量,从而先把宽度和高度不符合要求的给删掉二做的一部分工作。不得不感叹一下“人工”只能时代下苦逼的实习生。。。
File picture=new File("C:\\Users\\yejianan\\Desktop\\1.jpg");
        try {
            BufferedImage sourceImg = ImageIO.read(new FileInputStream(picture));
            int width=sourceImg.getWidth();
            int height=sourceImg.getHeight();
            System.out.println("width:"+width);
            System.out.println("height:"+height);
        }catch (Exception e){
            e.printStackTrace();
        }

猜你喜欢

转载自blog.csdn.net/icyyyer/article/details/80243393