How do I properly load a BufferedImage in java?

后端 未结 2 1441
无人及你
无人及你 2020-12-16 09:10

Okay, so I\'ve been trying to load a BufferedImage using this code:

URL url = this.getClass().getResource(\"test.png\");
BufferedImage img = (BufferedImage)          


        
相关标签:
2条回答
  • 2020-12-16 09:59
    BufferedImage img = null;
    try {
        img = ImageIO.read(new File("D:\\work\\files\\logo.jpg"));
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    
    0 讨论(0)
  • 2020-12-16 10:07

    Use ImageIO.read() instead:

    BufferedImage img = ImageIO.read(url);
    
    0 讨论(0)
提交回复
热议问题