Skip to content

Commit

Permalink
Render Pixel jobs to BufferedImage first
Browse files Browse the repository at this point in the history
Circumvents an OS X nearest-neghbor rendering bug.
Closes #38.
  • Loading branch information
tresf authored and Berenz committed Jun 29, 2016
1 parent 8dafb41 commit 7b8d27c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/qz/printer/action/PrintImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws
imgToPrint = rotate(imgToPrint, imageRotation);
}

Graphics2D graphics2D = withRenderHints((Graphics2D)graphics);
log.trace("{}", graphics2D.getRenderingHints());


// apply image scaling
double boundW = pageFormat.getImageableWidth();
double boundH = pageFormat.getImageableHeight();
Expand All @@ -165,8 +161,12 @@ public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws
log.trace("Image size: {},{}", imgW, imgH);

// Now we perform our rendering
graphics2D.drawImage(imgToPrint, (int)boundX, (int)boundY, (int)boundX + imgW, (int)boundY + imgH,
BufferedImage buffer = new BufferedImage((int)boundX + imgW, (int)boundY + imgH, imgToPrint.getType());
Graphics2D g2d = withRenderHints(buffer.createGraphics());
g2d.drawImage(imgToPrint, (int)boundX, (int)boundY, (int)boundX + imgW, (int)boundY + imgH,
0, 0, imgToPrint.getWidth(), imgToPrint.getHeight(), null);
graphics.drawImage(buffer, 0, 0, null);
g2d.dispose();

// Valid page
return PAGE_EXISTS;
Expand Down Expand Up @@ -208,6 +208,7 @@ private BufferedImage rotate(BufferedImage image, double angle) {
private Graphics2D withRenderHints(Graphics2D g2d) {
g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, interpolation);
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Expand Down

0 comments on commit 7b8d27c

Please sign in to comment.