List of usage examples for java.awt RenderingHints VALUE_ANTIALIAS_ON
Object VALUE_ANTIALIAS_ON
To view the source code for java.awt RenderingHints VALUE_ANTIALIAS_ON.
Click Source Link
From source file:com.igormaznitsa.jhexed.swing.editor.ui.exporters.PNGImageExporter.java
public BufferedImage generateImage() throws IOException { final int DEFAULT_CELL_WIDTH = 48; final int DEFAULT_CELL_HEIGHT = 48; final int imgWidth = this.docOptions.getImage() == null ? DEFAULT_CELL_WIDTH * this.docOptions.getColumns() : Math.round(this.docOptions.getImage().getSVGWidth()); final int imgHeight = this.docOptions.getImage() == null ? DEFAULT_CELL_HEIGHT * this.docOptions.getRows() : Math.round(this.docOptions.getImage().getSVGHeight()); final BufferedImage result; if (exportData.isBackgroundImageExport() && this.docOptions.getImage() != null) { result = this.docOptions.getImage().rasterize(imgWidth, imgHeight, BufferedImage.TYPE_INT_ARGB); } else {//from ww w.jav a 2 s . com result = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_ARGB); } final Graphics2D gfx = result.createGraphics(); gfx.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); gfx.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); final HexEngine<Graphics2D> engine = new HexEngine<Graphics2D>(DEFAULT_CELL_WIDTH, DEFAULT_CELL_HEIGHT, this.docOptions.getHexOrientation()); final List<HexFieldLayer> reversedNormalizedStack = new ArrayList<HexFieldLayer>(); for (int i = this.exportData.getLayers().size() - 1; i >= 0; i--) { final LayerExportRecord rec = this.exportData.getLayers().get(i); if (rec.isAllowed()) { reversedNormalizedStack.add(rec.getLayer()); } } if (Thread.currentThread().isInterrupted()) return null; final HexFieldValue[] stackOfValues = new HexFieldValue[reversedNormalizedStack.size()]; engine.setModel(new HexEngineModel<HexFieldValue[]>() { @Override public int getColumnNumber() { return docOptions.getColumns(); } @Override public int getRowNumber() { return docOptions.getRows(); } @Override public HexFieldValue[] getValueAt(final int col, final int row) { Arrays.fill(stackOfValues, null); for (int index = 0; index < reversedNormalizedStack.size(); index++) { stackOfValues[index] = reversedNormalizedStack.get(index).getHexValueAtPos(col, row); } return stackOfValues; } @Override public HexFieldValue[] getValueAt(final HexPosition pos) { return this.getValueAt(pos.getColumn(), pos.getRow()); } @Override public void setValueAt(int col, int row, HexFieldValue[] value) { } @Override public void setValueAt(HexPosition pos, HexFieldValue[] value) { } @Override public boolean isPositionValid(final int col, final int row) { return col >= 0 && col < docOptions.getColumns() && row >= 0 && row < docOptions.getRows(); } @Override public boolean isPositionValid(final HexPosition pos) { return this.isPositionValid(pos.getColumn(), pos.getRow()); } @Override public void attachedToEngine(final HexEngine<?> engine) { } @Override public void detachedFromEngine(final HexEngine<?> engine) { } }); final HexRect2D visibleSize = engine.getVisibleSize(); final float xcoeff = (float) result.getWidth() / visibleSize.getWidth(); final float ycoeff = (float) result.getHeight() / visibleSize.getHeight(); engine.setScale(xcoeff, ycoeff); final Image[][] cachedIcons = new Image[this.exportData.getLayers().size()][]; engine.setRenderer(new ColorHexRender() { private final Stroke stroke = new BasicStroke(docOptions.getLineWidth()); @Override public Stroke getStroke() { return this.stroke; } @Override public Color getFillColor(HexEngineModel<?> model, int col, int row) { return null; } @Override public Color getBorderColor(HexEngineModel<?> model, int col, int row) { return exportData.isExportHexBorders() ? docOptions.getColor() : null; } @Override public void drawExtra(HexEngine<Graphics2D> engine, Graphics2D g, int col, int row, Color borderColor, Color fillColor) { } @Override public void drawUnderBorder(final HexEngine<Graphics2D> engine, final Graphics2D g, final int col, final int row, final Color borderColor, final Color fillColor) { final HexFieldValue[] stackValues = (HexFieldValue[]) engine.getModel().getValueAt(col, row); for (int i = 0; i < stackValues.length; i++) { final HexFieldValue valueToDraw = stackValues[i]; if (valueToDraw == null) { continue; } g.drawImage(cachedIcons[i][valueToDraw.getIndex()], 0, 0, null); } } }); final Path2D hexShape = ((ColorHexRender) engine.getRenderer()).getHexPath(); final int cellWidth = hexShape.getBounds().width; final int cellHeight = hexShape.getBounds().height; for (int layerIndex = 0; layerIndex < reversedNormalizedStack.size() && !Thread.currentThread().isInterrupted(); layerIndex++) { final HexFieldLayer theLayer = reversedNormalizedStack.get(layerIndex); final Image[] cacheLineForLayer = new Image[theLayer.getHexValuesNumber()]; for (int valueIndex = 1; valueIndex < theLayer.getHexValuesNumber(); valueIndex++) { cacheLineForLayer[valueIndex] = theLayer.getHexValueForIndex(valueIndex).makeIcon(cellWidth, cellHeight, hexShape, true); } cachedIcons[layerIndex] = cacheLineForLayer; } engine.drawWithThreadInterruptionCheck(gfx); if (Thread.currentThread().isInterrupted()) return null; if (this.exportData.isCellCommentariesExport()) { final Iterator<Entry<HexPosition, String>> iterator = this.cellComments.iterator(); gfx.setFont(new Font("Arial", Font.BOLD, 12)); while (iterator.hasNext() && !Thread.currentThread().isInterrupted()) { final Entry<HexPosition, String> item = iterator.next(); final HexPosition pos = item.getKey(); final String text = item.getValue(); final float x = engine.calculateX(pos.getColumn(), pos.getRow()); final float y = engine.calculateY(pos.getColumn(), pos.getRow()); final Rectangle2D textBounds = gfx.getFontMetrics().getStringBounds(text, gfx); final float dx = x - ((float) textBounds.getWidth() - engine.getCellWidth()) / 2; gfx.setColor(Color.BLACK); gfx.drawString(text, dx, y); gfx.setColor(Color.WHITE); gfx.drawString(text, dx - 2, y - 2); } } gfx.dispose(); return result; }
From source file:com.igormaznitsa.jhexed.values.HexSVGImageValue.java
@Override public BufferedImage makeIcon(final int width, final int height, final Path2D shape, final boolean allowAlpha) { try {//from w w w . ja va2s. c o m final BufferedImage img = this.image.rasterize(width, height, BufferedImage.TYPE_INT_ARGB); if (shape == null) { return img; } else { final BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); final Graphics2D g = result.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); g.setClip(makeTransformedPathForSize(width, height, shape)); g.drawImage(img, 0, 0, null); g.dispose(); return result; } } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:peakml.util.swt.widget.IntensityTrendGraph.java
public BufferedImage getGraphImage(int width, int height) { BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = img.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); linechart.draw(g, new Rectangle(0, 0, width, height)); return img;// ww w. ja v a 2 s. c om }
From source file:forge.view.arcane.util.OutlinedLabel.java
/** {@inheritDoc} */ @Override//from www .ja v a2 s. c om public final void paint(final Graphics g) { if (getText().length() == 0) { return; } Dimension size = getSize(); // // if( size.width < 50 ) { // g.setColor(Color.cyan); // g.drawRect(0, 0, size.width-1, size.height-1); // } Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); int textX = outlineSize, textY = 0; int wrapWidth = Math.max(0, wrap ? size.width - outlineSize * 2 : Integer.MAX_VALUE); final String text = getText(); AttributedString attributedString = new AttributedString(text); if (!StringUtils.isEmpty(text)) { attributedString.addAttribute(TextAttribute.FONT, getFont()); } AttributedCharacterIterator charIterator = attributedString.getIterator(); FontRenderContext fontContext = g2d.getFontRenderContext(); LineBreakMeasurer measurer = new LineBreakMeasurer(charIterator, BreakIterator.getWordInstance(Locale.ENGLISH), fontContext); int lineCount = 0; while (measurer.getPosition() < charIterator.getEndIndex()) { measurer.nextLayout(wrapWidth); lineCount++; if (lineCount > 2) { break; } } charIterator.first(); // Use char wrap if word wrap would cause more than two lines of text. if (lineCount > 2) { measurer = new LineBreakMeasurer(charIterator, BreakIterator.getCharacterInstance(Locale.ENGLISH), fontContext); } else { measurer.setPosition(0); } while (measurer.getPosition() < charIterator.getEndIndex()) { TextLayout textLayout = measurer.nextLayout(wrapWidth); float ascent = textLayout.getAscent(); textY += ascent; // Move down to baseline. g2d.setColor(outlineColor); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f)); textLayout.draw(g2d, textX + outlineSize, textY - outlineSize); textLayout.draw(g2d, textX + outlineSize, textY + outlineSize); textLayout.draw(g2d, textX - outlineSize, textY - outlineSize); textLayout.draw(g2d, textX - outlineSize, textY + outlineSize); g2d.setColor(getForeground()); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); textLayout.draw(g2d, textX, textY); // Move down to top of next line. textY += textLayout.getDescent() + textLayout.getLeading(); } }
From source file:savant.view.tracks.ContinuousTrackRenderer.java
@Override public void render(Graphics2D g2, GraphPaneAdapter gp) throws RenderingException { renderPreCheck();/*from w w w . ja v a2 s . c om*/ AxisRange axisRange = (AxisRange) instructions.get(DrawingInstruction.AXIS_RANGE); gp.setXRange(axisRange.getXRange()); gp.setYRange(axisRange.getYRange()); if (gp.needsToResize()) return; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); ColourScheme cs = (ColourScheme) instructions.get(DrawingInstruction.COLOUR_SCHEME); Color fillcolor = cs.getColor(ColourKey.CONTINUOUS_FILL); Color linecolor = cs.getColor(ColourKey.CONTINUOUS_LINE); GeneralPath path = new GeneralPath(); double xFormXPos = Double.NaN, xFormYPos = Double.NaN; double yPixel0 = gp.transformYPos(0.0); LOG.debug("h=" + gp.getHeight() + ", yMin=" + gp.getYRange().getFrom() + ", unitHeight=" + gp.getUnitHeight() + " \u27A4 yPixel0=" + yPixel0); double maxData = 0; boolean haveOpenPath = false; boolean haveData = false; if (data != null) { for (int i = 0; i < data.size(); i++) { ContinuousRecord continuousRecord = (ContinuousRecord) data.get(i); int xPos = continuousRecord.getPosition(); float yPos = continuousRecord.getValue(); if (Float.isNaN(yPos)) { // Hit a position with no data. May need to close off the current path. if (haveOpenPath) { path.lineTo(xFormXPos, yPixel0); path.closePath(); haveOpenPath = false; } } else { haveData = true; xFormXPos = gp.transformXPos(xPos);//+gp.getUnitWidth()/2; xFormYPos = gp.transformYPos(yPos); if (!haveOpenPath) { // Start our path off with a vertical line. path.moveTo(xFormXPos, yPixel0); haveOpenPath = true; } path.lineTo(xFormXPos, xFormYPos); Rectangle2D rec = new Rectangle2D.Double( xFormXPos - ((xFormXPos - path.getCurrentPoint().getX()) / 2), 0, Math.max(xFormXPos - path.getCurrentPoint().getX(), 1), gp.getHeight()); recordToShapeMap.put(continuousRecord, rec); xFormXPos = gp.transformXPos(xPos + 1); path.lineTo(xFormXPos, xFormYPos); } if (yPos > maxData) { maxData = yPos; } } } if (!haveData) { throw new RenderingException("No data in range", RenderingException.INFO_PRIORITY); } if (haveOpenPath) { // Path needs to be closed. path.lineTo(xFormXPos, yPixel0); path.closePath(); } g2.setColor(fillcolor); g2.fill(path); g2.setColor(linecolor); g2.draw(path); if (axisRange.getYRange().getFrom() < 0) { g2.setColor(Color.darkGray); g2.draw(new Line2D.Double(0.0, yPixel0, gp.getWidth(), yPixel0)); } }
From source file:kz.supershiny.core.services.ImageService.java
/** * Creates thumb for image.//from w w w. j a v a2 s . c o m * * @param originalData original image in byte array * @param type original - 0, large - 1, small - 2 * @return resized image in byte array */ public static byte[] resizeImage(byte[] originalData, ImageSize type) { //if original flag, then return original if (type.equals(ImageSize.ORIGINAL)) { return originalData; } BufferedImage originalImage = null; BufferedImage resizedImage = null; byte[] result = null; //convert bytes to BufferedImage try (InputStream in = new ByteArrayInputStream(originalData)) { originalImage = ImageIO.read(in); } catch (IOException ex) { LOG.error("Cannot convert byte array to BufferedImage!", ex); return null; } //get original size int scaledHeight = originalImage.getHeight(); int scaledWidth = originalImage.getWidth(); switch (type) { case LARGE: scaledWidth = LARGE_WIDTH; scaledHeight = LARGE_HEIGHT; break; case SMALL: scaledWidth = SMALL_WIDTH; scaledHeight = SMALL_HEIGHT; break; default: break; } //calculate aspect ratio float ratio = 1.0F * originalImage.getWidth() / originalImage.getHeight(); if (ratio > 1.0F) { scaledHeight = (int) (scaledHeight / ratio); } else { scaledWidth = (int) (scaledWidth * ratio); } //resize with hints resizedImage = new BufferedImage(scaledWidth, scaledHeight, originalImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : originalImage.getType()); Graphics2D g = resizedImage.createGraphics(); g.drawImage(originalImage, 0, 0, scaledWidth, scaledHeight, null); g.dispose(); g.setComposite(AlphaComposite.Src); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //convert BufferedImage to bytes try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { ImageIO.write(resizedImage, "png", baos); baos.flush(); result = baos.toByteArray(); } catch (IOException ex) { LOG.error("Cannot convert BufferedImage to byte array!", ex); } return result; }
From source file:org.shredzone.commons.captcha.impl.DefaultCaptchaGenerator.java
@Override public BufferedImage createCaptcha(char[] text) { if (text == null || text.length == 0) { throw new IllegalArgumentException("No captcha text given"); }/*from www.j a va 2 s . c om*/ BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = image.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setBackground(Color.WHITE); g2d.setColor(Color.BLACK); clearCanvas(g2d); if (showGrid) { drawGrid(g2d); } int charMaxWidth = width / text.length; int xPos = 0; for (char ch : text) { drawCharacter(g2d, ch, xPos, charMaxWidth); xPos += charMaxWidth; } g2d.dispose(); return image; }
From source file:org.deeplearning4j.examples.multigpu.video.VideoGenerator.java
private static int[] generateVideo(String path, int nFrames, int width, int height, int numShapes, Random r, boolean backgroundNoise, int numDistractorsPerFrame) throws Exception { //First: decide where transitions between one shape and another are double[] rns = new double[numShapes]; double sum = 0; for (int i = 0; i < numShapes; i++) { rns[i] = r.nextDouble();/*from ww w .j a va 2s . c o m*/ sum += rns[i]; } for (int i = 0; i < numShapes; i++) rns[i] /= sum; int[] startFrames = new int[numShapes]; startFrames[0] = 0; for (int i = 1; i < numShapes; i++) { startFrames[i] = (int) (startFrames[i - 1] + MIN_FRAMES + rns[i] * (nFrames - numShapes * MIN_FRAMES)); } //Randomly generate shape positions, velocities, colors, and type int[] shapeTypes = new int[numShapes]; int[] initialX = new int[numShapes]; int[] initialY = new int[numShapes]; double[] velocityX = new double[numShapes]; double[] velocityY = new double[numShapes]; Color[] color = new Color[numShapes]; for (int i = 0; i < numShapes; i++) { shapeTypes[i] = r.nextInt(NUM_SHAPES); initialX[i] = SHAPE_MIN_DIST_FROM_EDGE + r.nextInt(width - SHAPE_SIZE - 2 * SHAPE_MIN_DIST_FROM_EDGE); initialY[i] = SHAPE_MIN_DIST_FROM_EDGE + r.nextInt(height - SHAPE_SIZE - 2 * SHAPE_MIN_DIST_FROM_EDGE); velocityX[i] = -1 + 2 * r.nextDouble(); velocityY[i] = -1 + 2 * r.nextDouble(); color[i] = new Color(r.nextFloat(), r.nextFloat(), r.nextFloat()); } //Generate a sequence of BufferedImages with the given shapes, and write them to the video SequenceEncoder enc = new SequenceEncoder(new File(path)); int currShape = 0; int[] labels = new int[nFrames]; for (int i = 0; i < nFrames; i++) { if (currShape < numShapes - 1 && i >= startFrames[currShape + 1]) currShape++; BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = bi.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setBackground(Color.BLACK); if (backgroundNoise) { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { bi.setRGB(x, y, new Color(r.nextFloat() * MAX_NOISE_VALUE, r.nextFloat() * MAX_NOISE_VALUE, r.nextFloat() * MAX_NOISE_VALUE).getRGB()); } } } g2d.setColor(color[currShape]); //Position of shape this frame int currX = (int) (initialX[currShape] + (i - startFrames[currShape]) * velocityX[currShape] * MAX_VELOCITY); int currY = (int) (initialY[currShape] + (i - startFrames[currShape]) * velocityY[currShape] * MAX_VELOCITY); //Render the shape switch (shapeTypes[currShape]) { case 0: //Circle g2d.fill(new Ellipse2D.Double(currX, currY, SHAPE_SIZE, SHAPE_SIZE)); break; case 1: //Square g2d.fill(new Rectangle2D.Double(currX, currY, SHAPE_SIZE, SHAPE_SIZE)); break; case 2: //Arc g2d.fill(new Arc2D.Double(currX, currY, SHAPE_SIZE, SHAPE_SIZE, 315, 225, Arc2D.PIE)); break; case 3: //Line g2d.setStroke(lineStroke); g2d.draw(new Line2D.Double(currX, currY, currX + SHAPE_SIZE, currY + SHAPE_SIZE)); break; default: throw new RuntimeException(); } //Add some distractor shapes, which are present for one frame only for (int j = 0; j < numDistractorsPerFrame; j++) { int distractorShapeIdx = r.nextInt(NUM_SHAPES); int distractorX = DISTRACTOR_MIN_DIST_FROM_EDGE + r.nextInt(width - SHAPE_SIZE); int distractorY = DISTRACTOR_MIN_DIST_FROM_EDGE + r.nextInt(height - SHAPE_SIZE); g2d.setColor(new Color(r.nextFloat(), r.nextFloat(), r.nextFloat())); switch (distractorShapeIdx) { case 0: g2d.fill(new Ellipse2D.Double(distractorX, distractorY, SHAPE_SIZE, SHAPE_SIZE)); break; case 1: g2d.fill(new Rectangle2D.Double(distractorX, distractorY, SHAPE_SIZE, SHAPE_SIZE)); break; case 2: g2d.fill(new Arc2D.Double(distractorX, distractorY, SHAPE_SIZE, SHAPE_SIZE, 315, 225, Arc2D.PIE)); break; case 3: g2d.setStroke(lineStroke); g2d.draw(new Line2D.Double(distractorX, distractorY, distractorX + SHAPE_SIZE, distractorY + SHAPE_SIZE)); break; default: throw new RuntimeException(); } } enc.encodeImage(bi); g2d.dispose(); labels[i] = shapeTypes[currShape]; } enc.finish(); //write .mp4 return labels; }
From source file:ImageOps.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); int w = getSize().width; int h = getSize().height; g2.setColor(Color.black);//from w w w. j ava 2s . co m float[][] data = { { 0.1f, 0.1f, 0.1f, // low-pass filter 0.1f, 0.2f, 0.1f, 0.1f, 0.1f, 0.1f }, SHARPEN3x3_3 }; String theDesc[] = { "Convolve LowPass", "Convolve Sharpen", "LookupOp", "RescaleOp" }; for (int i = 0; i < bi.length; i++) { int iw = bi[i].getWidth(this); int ih = bi[i].getHeight(this); int x = 0, y = 0; AffineTransform at = new AffineTransform(); at.scale((w - 14) / 2.0 / iw, (h - 34) / 2.0 / ih); BufferedImageOp biop = null; BufferedImage bimg = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB); switch (i) { case 0: case 1: x = i == 0 ? 5 : w / 2 + 3; y = 15; Kernel kernel = new Kernel(3, 3, data[i]); ConvolveOp cop = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null); cop.filter(bi[i], bimg); biop = new AffineTransformOp(at, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); break; case 2: x = 5; y = h / 2 + 15; byte chlut[] = new byte[256]; for (int j = 0; j < 200; j++) chlut[j] = (byte) (256 - j); ByteLookupTable blut = new ByteLookupTable(0, chlut); LookupOp lop = new LookupOp(blut, null); lop.filter(bi[i], bimg); biop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR); break; case 3: x = w / 2 + 3; y = h / 2 + 15; RescaleOp rop = new RescaleOp(1.1f, 20.0f, null); rop.filter(bi[i], bimg); biop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR); } g2.drawImage(bimg, biop, x, y); TextLayout tl = new TextLayout(theDesc[i], g2.getFont(), g2.getFontRenderContext()); tl.draw(g2, (float) x, (float) y - 4); } }
From source file:org.apache.pdflens.views.pagesview.PageDrawer.java
/** * This will draw the page to the requested context. * * @param g The graphics context to draw onto. * @param p The page to draw./*from w w w . ja va 2 s .c om*/ * @param pageDimension The size of the page to draw. * * @throws IOException If there is an IO error while drawing the page. */ public void drawPage(Graphics g, PDPage p, Dimension pageDimension) throws IOException { graphics = (Graphics2D) g; page = p; pageSize = pageDimension; graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); // Only if there is some content, we have to process it. // Otherwise we are done here and we will produce an empty page if (page.getContents() != null) { PDResources resources = page.findResources(); processStream(page, resources, page.getContents().getStream()); } List annotations = page.getAnnotations(); for (int i = 0; i < annotations.size(); i++) { PDAnnotation annot = (PDAnnotation) annotations.get(i); PDRectangle rect = annot.getRectangle(); String appearanceName = annot.getAppearanceStream(); PDAppearanceDictionary appearDictionary = annot.getAppearance(); if (appearDictionary != null) { if (appearanceName == null) { appearanceName = "default"; } Map appearanceMap = appearDictionary.getNormalAppearance(); PDAppearanceStream appearance = (PDAppearanceStream) appearanceMap.get(appearanceName); if (appearance != null) { g.translate((int) rect.getLowerLeftX(), (int) -rect.getLowerLeftY()); processSubStream(page, appearance.getResources(), appearance.getStream()); g.translate((int) -rect.getLowerLeftX(), (int) +rect.getLowerLeftY()); } } } }