Well, I have an image and I want to print it in exactly real size on paper and implement the code below, but I donβt know why this code enlarges the image, but I want the image to keep its size, could you help me
Thanks a lot...
final Image img = new ImageIcon("C:\\check.jpg").getImage(); PrinterJob printJob = PrinterJob.getPrinterJob(); printJob.setPrintable(new Printable() { public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException { if (pageIndex != 0) { return NO_SUCH_PAGE; } graphics.drawImage(img, 0, 0, img.getWidth(null), img.getHeight(null), null); return PAGE_EXISTS; } }); if (printJob.printDialog()) { try { printJob.print(); } catch (Exception prt) { System.err.println(prt.getMessage()); } }
source share