Domanda

Okay, quindi ho provato a caricare un'immagine bufferizzata usando questo codice:

URL url = this.getClass().getResource("test.png");
BufferedImage img = (BufferedImage) Toolkit.getDefaultToolkit().getImage(url);

Questo mi dà un errore di cast del tipo quando lo eseguo, quindi come posso caricare correttamente un BufferedImage?

È stato utile?

Soluzione

Usa ImageIO.read () invece:

BufferedImage img = ImageIO.read(url);

Altri suggerimenti

BufferedImage img = null;
try {
    img = ImageIO.read(new File("D:\\work\\files\\logo.jpg"));
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top