使用java netbeans从JLabel(使用Printer)打印图像



我正在使用java netbeans,并希望从JLabel打印图像,但它不工作。如果我用TextArea.print(),它是有效的。我只是想打印图像,请帮助。

Icon icon = noskha_kamilaa.getIcon();
BufferedImage bi=new BufferedImage(icon.getIconWidth(),icon.getIconHeight(),BufferedImage.TYPE_INT_RGB);
Graphics g=bi.createGraphics();
g.dispose();
try{ 
    printAll(g);
    JOptionPane.showMessageDialog(null, "success");
}catch(java.awt.print.PrinterException  e)      // give an error
{       
    System.err.format("Cannot print %%n", e.getMessage());   
}

在打印前处理图形对象

g.dispose();
try{ 
    printAll(g);
    JOptionPane.showMessageDialog(null, "success");
}catch(java.awt.print.PrinterException  e)      // give an error
{       
    System.err.format("Cannot print %%n", e.getMessage());   
}
应该

try{ 
    printAll(g);
    JOptionPane.showMessageDialog(null, "success");
    g.dispose();
}catch(java.awt.print.PrinterException  e)      // give an error
{       
    System.err.format("Cannot print %%n", e.getMessage());   
}

最新更新