java - JavaFX Printable to Image very pix-elated, but perfect to printer -


I have a printable object that prints perfectly fine on the printer, but when I put it in an image Print, so this is a lot pixelated?

Printing and an image

  Personal Page Format Setup Printer () {// Sizing (standard size is 72 dpi, so many inches from this) Double height = 4d * 72 D; Double width = 3d * 72d; Double margin = 0.1d * 72d; // Now lets print it AttributeSet attributes = new HashAttributeSet (); Attributes.add (new copies (1)); Printer Job printJob = PrinterJob.getPrinterJob (); Page Format Page Format = PrintJob.Default Page (); // If there are more than 10 items, the paper size is 6 inches // It will handle 24 different items if (1 == 2) height = 6d * 72d; // set page size paper paper = page format. Gadgetpaper (); Paper.setSize (width, height); Paper .Setmezzleearia (margin, margin, width - (margin * 2), height - (margin * 2)); // Set Orientation and Paper Page Format .setOrmentation (Page Format. Portrait); PageFormat.setPaper (paper); Return page format; } Private Zero Printtoimage () {MyPrintable myPrintable = New MyPrintable (); // Our Printer Page Format Page Format = Setup Printer (); // setViewView's size, intersects and width values ​​using double effect. Heat = Page Format.GateHight (); Double imageview = page format .getWidth (); // Make our image / graphics BufferedImage image = new BufferedImage ((int) imageWidth, (int) imageHeight, BufferedImage.TYPE_INT_ARGB); Graphics graphics = image.getGraphics (); // Color background white graphics. Setting (Color. WHITE); (Graphics 2D) Graphics) .Fill (new rectangle float (0, 0, (float) imagewood, (float) image hight)); // Call our print method directly, pass the graphics, try the page format and page index {myPrintable.print (graphics, page format, 0); } Catch (Printer exception e) {// Todo Auto-Generate Catch Block e.printStackTrace (); } Graphics.dispose (); // Set our image imgReport.setImage (SwingFXUtils.toFXImage (image, blank); // Now shows us the preview pane report. Pen .Setable (true); } Public Zero Print Print Printer (PrinterJob printJob = PrinterJob.getPrinterJob (); Page Format Page Format = Setup Printer (); PrintJob.setPrintable (new MyPrintable (), Page Format); Try {printJob.print (); } Hold (exception e) {e.printStackTrace (); }} Public MyPrintable () {Public Int Print (Graphics Graphics, Page Format Page Format, Int Page Index) Throws PrinterException {if (pageIndex> 0) {return NO_SUCH_PAGE; } // The user (0,0) is usually out of the image area, so we have to translate the X and Y values ​​into the page format to avoid computing graphics 2D g2d = (Graphics2D) graphics; G2d.translate (pageFormat.getImageableX), page format.gateimageable Y ()); // Add text here ........}}  

Here's how it is pixelated. It fits perfectly into the image ....

Enter image details here

You can use a controlled rendering quality to read it:

< / P>

Examples for your code:

  Graphics 2D graphics = (Graphics 2D) image.getGraphics (); Rendering hunts rh = new rendering hunt (rendering hints. KEY_ANTIALASING, rendering hints. VALUE_ANTIALIAS_ON); G2.setRenderingHints (RH); Graphics.setColor (Color.WHITE); Graphics .Fill (new rectangle float (0, 0, (float) imagewood, (float) image hight));  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -