Print image with actual size in java

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()); } } 
+2
source share
1 answer

Perhaps this is due to the fact that your image does not have the correct permission. Google "dpi" or "image resolution" and then look at the javadoc for PageFormat , which obviously uses a resolution of 72 dpi. You should now have enough information to properly scale the image.

+1
source

Source: https://habr.com/ru/post/1411072/


All Articles