如何用Java得到图片文件如jpg、bmp的尺寸(长宽)

解决方案 »

  1.   

    ImageIcon image = new ImageIcon("xxx");/*location*/
    int height = image.getIconHeight();
    int width = image.getIconWidth();
      

  2.   

    ImageIcon image=new ImageIcon............ 
    int height=image.getHeight(this);
    int width=image.getWidth(this);
      

  3.   

    File image= new File(ImageFileName);
    InputStream fileIn = new FileInputStream(image);
    JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(fileIn);
    BufferedImage bufImage = decoder.decodeAsBufferedImage();
    int width = bufImage.getWidth();
    int height = bufImage.getHeight();