Load image from a filepath via BufferedImage

前端 未结 5 1109
耶瑟儿~
耶瑟儿~ 2020-12-20 12:01

I have a problem with Java application, particular in loading a image from a location in my computer.

Following this post I used a BufferedImage and a <

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-20 12:34

    To find the image Width, height and size

    BufferedImage image = null;    
    int imageWidth = -1;
    int imageHeight = -1;
    int fileSize = -1;
    try {
        File imageFile = new File(imagePath);
        int fileSize = (int) imageFile.length();
        image = ImageIO.read(imageFile); // Reading the Image from the file system
        imageWidth = image.getWidth();
        imageHeight = image.getHeight();
    } catch (IOException e) {
        e.printStackTrace();
    }
    

提交回复
热议问题