2011-08-15 36 views
0

我已經編寫了能讓我打印框架的代碼,但現在我想使用printJob,因爲它爲用戶提供了更多的打印選項(如選擇要使用的打印機) 。有沒有一種快速的方法將BufferedImage轉換爲Printable,以便我可以在我的代碼中使用printjob? THX如何將BufferedImage轉換爲Printable,以便我可以使用printJob

if(command.equals("Print")){ 
     //saves image as temp and then prints it 

    File out = new File("temp.jpg"); 
    BufferedImage myImage = new BufferedImage((int) frame.getWidth(), 
         (int) frame.getHeight(), 
         BufferedImage.TYPE_INT_RGB); 

    frame.paintAll(myImage.createGraphics()); 
    try{ 
     ImageIO.write(myImage, "jpg", out); 
     PrintImage.printImage("temp.jpg"); 
    }catch (IOException exception){ 
     exception.printStackTrace(); 
    } catch (Exception e2) { 
     e2.printStackTrace(); 
    } 
} 

回答

相關問題