【问题标题】:read and jlabel set icon a image with different extension .001读取和 jlabel 设置图标具有不同扩展名 .001 的图像
【发布时间】:2013-07-31 08:36:34
【问题描述】:
    File file = new File("C:\\registro_sql\\Imagens\\Livro02\\0000\\000011.001");  
BufferedImage bufferedImage = null;  
try {  
    bufferedImage = ImageIO.read(file);  
     Icon icon = (Icon) bufferedImage;  
    lblImageIcon.setIcon(icon);  
} catch (IOException ex) {  
    JOptionPane.showMessageDialog(null, "ERRO!");  
}  

错误:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
Unhandled exception type IOException

at certidoesOrganizado.executor.main(executor.java:6)

我有一些扩展名为 .001、.002、.003 的文件,但这些文件只是图像,但我无法重命名它,因为另一个软件使用它们,但我想使用 java 来显示该图像文件,任何想法由于 BufferedImage 没有显示任何内容,它只是返回一个错误

【问题讨论】:

    标签: java swing jlabel bufferedimage


    【解决方案1】:

    该错误与问题中的代码无关,因为这表明IOException 有一个try/catch 块。该错误可能是由未显示的代码产生的。

    还有这个说法

    Icon icon = (Icon) bufferedImage;
    

    将导致ClassCastException,因为BufferedImage 不是Icon 类型。

    替换

    lblImageIcon.setIcon(icon);  
    

    与

    lblImageIcon.setIcon(new ImageIcon(bufferedImage));
    

    【讨论】:

      猜你喜欢
      • 2015-11-15
      • 1970-01-01
      • 2018-12-12
      • 1970-01-01
      • 2011-05-16
      • 1970-01-01
      • 1970-01-01
      • 2013-06-02
      • 2013-05-20
      相关资源
      最近更新 更多