I have already written code that will let me print my frame, but now I want to use printJob since it gives user more print option(such as selecting which printer to use). Is there a quick way to covert BufferedImage to Printable so i can use printjob in my code? thx
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();
}
}
You can use getGraphics to get the frame’s underlying Graphics object, then pass that to the print method of a PrinterJob.