Java Code Examples for java.awt.geom.AffineTransform#getScaleInstance()
The following examples show how to use
java.awt.geom.AffineTransform#getScaleInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StandardGlyphVector.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
private void initFontData() { font2D = FontUtilities.getFont2D(font); float s = font.getSize2D(); if (font.isTransformed()) { ftx = font.getTransform(); if (ftx.getTranslateX() != 0 || ftx.getTranslateY() != 0) { addFlags(FLAG_HAS_POSITION_ADJUSTMENTS); } ftx.setTransform(ftx.getScaleX(), ftx.getShearY(), ftx.getShearX(), ftx.getScaleY(), 0, 0); ftx.scale(s, s); } else { ftx = AffineTransform.getScaleInstance(s, s); } frctx = frc.getTransform(); resetDTX(getNonTranslateTX(frctx)); }
Example 2
Source File: Util.java From r2cloud with Apache License 2.0 | 6 votes |
public static void rotateImage(File result) { try { BufferedImage image; try (FileInputStream fis = new FileInputStream(result)) { image = ImageIO.read(fis); } AffineTransform tx = AffineTransform.getScaleInstance(-1, -1); tx.translate(-image.getWidth(null), -image.getHeight(null)); AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); image = op.filter(image, null); try (FileOutputStream fos = new FileOutputStream(result)) { ImageIO.write(image, "jpg", fos); } } catch (Exception e) { LOG.error("unable to rotate image", e); } }
Example 3
Source File: JFreeChart.java From ccu-historian with GNU General Public License v3.0 | 6 votes |
/** * Creates and returns a buffered image into which the chart has been drawn. * * @param imageWidth the image width. * @param imageHeight the image height. * @param drawWidth the width for drawing the chart (will be scaled to * fit image). * @param drawHeight the height for drawing the chart (will be scaled to * fit image). * @param info optional object for collection chart dimension and entity * information. * * @return A buffered image. */ public BufferedImage createBufferedImage(int imageWidth, int imageHeight, double drawWidth, double drawHeight, ChartRenderingInfo info) { BufferedImage image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = image.createGraphics(); double scaleX = imageWidth / drawWidth; double scaleY = imageHeight / drawHeight; AffineTransform st = AffineTransform.getScaleInstance(scaleX, scaleY); g2.transform(st); draw(g2, new Rectangle2D.Double(0, 0, drawWidth, drawHeight), null, info); g2.dispose(); return image; }
Example 4
Source File: StandardGlyphVector.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
private void initFontData() { font2D = FontUtilities.getFont2D(font); float s = font.getSize2D(); if (font.isTransformed()) { ftx = font.getTransform(); if (ftx.getTranslateX() != 0 || ftx.getTranslateY() != 0) { addFlags(FLAG_HAS_POSITION_ADJUSTMENTS); } ftx.setTransform(ftx.getScaleX(), ftx.getShearY(), ftx.getShearX(), ftx.getScaleY(), 0, 0); ftx.scale(s, s); } else { ftx = AffineTransform.getScaleInstance(s, s); } frctx = frc.getTransform(); resetDTX(getNonTranslateTX(frctx)); }
Example 5
Source File: GanttPrintable.java From ganttproject with GNU General Public License v3.0 | 5 votes |
/** Print the page */ @Override public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) { System.err.println("[GanttPrintable] print(): reduceFactor=" + reduceFactor); System.err.println("[GanttPrintable] print(): image: w=" + image.getWidth() + " h=" + image.getHeight()); System.err.println("[GanttPrintable] print(): page=" + pageIndex); int pagesPerRow = (int) (image.getWidth() / reduceFactor / pageFormat.getImageableWidth() + 1); int numRows = (int) (image.getHeight() / reduceFactor / pageFormat.getImageableHeight() + 1); System.err.println("[GanttPrintable] print(): numrows=" + numRows + " pagesPerRow=" + pagesPerRow); int totalPages = pagesPerRow * numRows; if (pageIndex >= totalPages) { return Printable.NO_SUCH_PAGE; } int currentRow = pageIndex / pagesPerRow; int currentColumn = pageIndex - currentRow * pagesPerRow; System.err.println("[GanttPrintable] print(): curentpage=" + currentColumn + " current row=" + currentRow); int leftx = (int) (currentColumn * (pageFormat.getImageableWidth() * reduceFactor - 2 / 3 * pageFormat.getImageableX())); int topy = (int) (currentRow * pageFormat.getImageableHeight() * reduceFactor); System.err.println("[GanttPrintable] print(): leftx=" + leftx + " topy=" + topy); Graphics2D g2d = (Graphics2D) graphics; g2d.setClip((int) pageFormat.getImageableX(), (int) pageFormat.getImageableY(), (int) pageFormat.getImageableWidth(), (int) pageFormat.getImageableHeight()); AffineTransform transform = AffineTransform.getScaleInstance(1 / reduceFactor, 1 / reduceFactor); transform.translate(pageFormat.getImageableX() - leftx, pageFormat.getImageableY() - topy); g2d.drawRenderedImage(image, transform); return Printable.PAGE_EXISTS; }
Example 6
Source File: Photo.java From javaanpr with Educational Community License v2.0 | 5 votes |
public static BufferedImage linearResizeBi(BufferedImage origin, int width, int height) { BufferedImage resizedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g = resizedImage.createGraphics(); float xScale = (float) width / origin.getWidth(); float yScale = (float) height / origin.getHeight(); AffineTransform at = AffineTransform.getScaleInstance(xScale, yScale); g.drawRenderedImage(origin, at); g.dispose(); return resizedImage; }
Example 7
Source File: LoginDialog.java From Spark with Apache License 2.0 | 5 votes |
/** * Uses the Spark logo to paint as the background. * * @param g the graphics to use. */ @Override public void paintComponent(Graphics g) { final Image backgroundImage = icons.getImage(); final double scaleX = getWidth() / (double)backgroundImage.getWidth(null); final double scaleY = getHeight() / (double)backgroundImage.getHeight(null); AffineTransform xform = AffineTransform.getScaleInstance(scaleX, scaleY); ((Graphics2D)g).drawImage(backgroundImage, xform, this); }
Example 8
Source File: CardsPicPanel.java From MtgDesktopCompanion with GNU General Public License v3.0 | 5 votes |
private BufferedImage mirroring(BufferedImage image) { AffineTransform tx = AffineTransform.getScaleInstance(-1, 1); tx.translate(-image.getWidth(null), 0); AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); image = op.filter(image, null); return image; }
Example 9
Source File: RVizVisualization.java From coordination_oru with GNU General Public License v3.0 | 5 votes |
private BufferedImage flipHorizontally(BufferedImage imgIn) { AffineTransform tx = AffineTransform.getScaleInstance(-1, 1); tx.translate(-imgIn.getWidth(null), 0); AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); imgIn = op.filter(imgIn, null); return imgIn; }
Example 10
Source File: ImageUtils.java From visualvm with GNU General Public License v2.0 | 5 votes |
final public static BufferedImage resizeImage(BufferedImage img, int width, int height) { Graphics2D gin = img.createGraphics(); GraphicsConfiguration gc = gin.getDeviceConfiguration(); gin.dispose(); BufferedImage dst = gc.createCompatibleImage(width, height, BufferedImage.BITMASK); Graphics2D gr = dst.createGraphics(); gr.setComposite(AlphaComposite.Src); AffineTransform at = AffineTransform.getScaleInstance((double)width/img.getWidth(), (double)height/img.getHeight()); gr.drawRenderedImage(img,at); return dst; }
Example 11
Source File: IncorrectClipXorModeSurface2Surface.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public static void main(final String[] args) throws IOException { GraphicsEnvironment ge = GraphicsEnvironment .getLocalGraphicsEnvironment(); GraphicsConfiguration gc = ge.getDefaultScreenDevice() .getDefaultConfiguration(); AffineTransform at; for (int size : SIZES) { at = AffineTransform.getScaleInstance(size, size); for (Shape clip : SHAPES) { clip = at.createTransformedShape(clip); for (Shape to : SHAPES) { to = at.createTransformedShape(to); // Prepare test images BufferedImage snapshot; VolatileImage source = getVolatileImage(gc, size); VolatileImage target = getVolatileImage(gc, size); int attempt = 0; while (true) { if (++attempt > 10) { throw new RuntimeException("Too many attempts: " + attempt); } // Prepare source images source.validate(gc); Graphics2D g2d = source.createGraphics(); g2d.setColor(Color.RED); g2d.fillRect(0, 0, size, size); g2d.dispose(); if (source.validate(gc) != VolatileImage.IMAGE_OK) { continue; } // Prepare target images target.validate(gc); g2d = target.createGraphics(); g2d.setColor(Color.GREEN); g2d.fillRect(0, 0, size, size); g2d.dispose(); if (target.validate(gc) != VolatileImage.IMAGE_OK) { continue; } draw(clip, to, source, target); snapshot = target.getSnapshot(); if (source.contentsLost() || target.contentsLost()) { continue; } break; } // Prepare gold images BufferedImage goldS = getSourceGold(gc, size); BufferedImage goldT = getTargetGold(gc, size); draw(clip, to, goldS, goldT); validate(snapshot, goldT); source.flush(); target.flush(); } } } }
Example 12
Source File: WPathGraphics.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
private void textOut(String str, Font font, PhysicalFont font2D, FontRenderContext frc, float deviceSize, int rotation, float awScale, double scaleFactorX, double scaleFactorY, float userx, float usery, float devx, float devy, float targetW) { String family = font2D.getFamilyName(null); int style = font.getStyle() | font2D.getStyle(); WPrinterJob wPrinterJob = (WPrinterJob)getPrinterJob(); boolean setFont = wPrinterJob.setFont(family, deviceSize, style, rotation, awScale); if (!setFont) { super.drawString(str, userx, usery, font, frc, targetW); return; } float[] glyphPos = null; if (!okGDIMetrics(str, font, frc, scaleFactorX)) { /* If there is a 1:1 char->glyph mapping then char positions * are the same as glyph positions and we can tell GDI * where to place the glyphs. * On drawing we remove control chars so these need to be * removed now so the string and positions are the same length. * For other cases we need to pass glyph codes to GDI. */ str = wPrinterJob.removeControlChars(str); char[] chars = str.toCharArray(); int len = chars.length; GlyphVector gv = null; if (!FontUtilities.isComplexText(chars, 0, len)) { gv = font.createGlyphVector(frc, str); } if (gv == null) { super.drawString(str, userx, usery, font, frc, targetW); return; } glyphPos = gv.getGlyphPositions(0, len, null); Point2D gvAdvPt = gv.getGlyphPosition(gv.getNumGlyphs()); /* GDI advances must not include device space rotation. * See earlier comment in printGlyphVector() for details. */ AffineTransform advanceTransform = AffineTransform.getScaleInstance(scaleFactorX, scaleFactorY); float[] glyphAdvPos = new float[glyphPos.length]; advanceTransform.transform(glyphPos, 0, //source glyphAdvPos, 0, //destination glyphPos.length/2); //num points glyphPos = glyphAdvPos; } wPrinterJob.textOut(str, devx, devy, glyphPos); }
Example 13
Source File: ScaleClipTest.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
private static void testNegativeScale(final BufferedImage image, final SCALE_MODE mode) { final Graphics2D g2d = (Graphics2D) image.getGraphics(); try { g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); g2d.setBackground(Color.WHITE); g2d.clearRect(0, 0, SIZE, SIZE); g2d.setColor(Color.BLACK); // Bug in TransformingPathConsumer2D.adjustClipScale() // non ortho scale only final double scale = -1.0; final AffineTransform at; switch (mode) { default: case ORTHO: at = AffineTransform.getScaleInstance(scale, scale); break; case NON_ORTHO: at = AffineTransform.getScaleInstance(scale, scale + 1e-5); break; case COMPLEX: at = AffineTransform.getScaleInstance(scale, scale); at.concatenate(AffineTransform.getShearInstance(1e-4, 1e-4)); break; } g2d.setTransform(at); // Set cap/join to reduce clip margin: g2d.setStroke(new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); final Path2D p = new Path2D.Double(); p.moveTo(scale * 10, scale * 10); p.lineTo(scale * (SIZE - 10), scale * (SIZE - 10)); g2d.draw(p); if (SAVE_IMAGE) { try { final File file = new File("ScaleClipTest-testNegativeScale-" + mode + ".png"); System.out.println("Writing file: " + file.getAbsolutePath()); ImageIO.write(image, "PNG", file); } catch (IOException ioe) { ioe.printStackTrace(); } } // Check image: // 25, 25 = black checkPixel(image.getData(), 25, 25, Color.BLACK.getRGB()); } finally { g2d.dispose(); } }
Example 14
Source File: bug8038000.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
private void checkOps() throws Exception { RasterOp[] ops = new RasterOp[] { new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_sRGB), ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), null), new AffineTransformOp(AffineTransform.getScaleInstance(1, 1.1), null) }; for (RasterOp op: ops) { // Banded rasters checkOp(Raster.createBandedRaster(DataBuffer.TYPE_BYTE, 10, 1, 10, new int[] {0, 1, 2}, new int[]{2,1,0}, null), Raster.createBandedRaster(DataBuffer.TYPE_BYTE, 10, 1, 1001, new int[] {0, 1, 2}, new int[]{2,1,0}, null), op); checkOp(Raster.createBandedRaster(DataBuffer.TYPE_USHORT, 10, 1, 10, new int[] {0, 1, 2}, new int[]{2,1,0}, null), Raster.createBandedRaster(DataBuffer.TYPE_USHORT, 10, 1, 1001, new int[] {0, 1, 2}, new int[]{2,1,0}, null), op); checkOp(Raster.createBandedRaster(DataBuffer.TYPE_INT, 10, 1, 10, new int[] {0, 1, 2}, new int[]{2,1,0}, null), Raster.createBandedRaster(DataBuffer.TYPE_INT, 10, 1, 1001, new int[] {0, 1, 2}, new int[]{2,1,0}, null), op); // Interleaved rasters checkOp(Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, 10, 1, 30, 3, new int[]{0, 1, 2}, null), Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, 10, 1, 1001, 3, new int[]{0, 1, 2}, null), op); checkOp(Raster.createInterleavedRaster(DataBuffer.TYPE_USHORT, 10, 1, 30, 3, new int[]{0, 1, 2}, null), Raster.createInterleavedRaster(DataBuffer.TYPE_USHORT, 10, 1, 1001, 3, new int[]{0, 1, 2}, null), op); // Packed rasters checkOp(Raster.createPackedRaster(new DataBufferByte(10), 10, 1, 10, new int[] {0x01, 0x02, 0x04}, null), Raster.createPackedRaster(new DataBufferByte(10), 10, 1, 2000, new int[] {0x01, 0x02, 0x04}, null), op); checkOp(Raster.createPackedRaster(new DataBufferInt(10), 10, 1, 10, new int[] {0xff0000, 0x00ff00, 0x0000ff}, null), Raster.createPackedRaster(new DataBufferInt(10), 10, 1, 20, new int[] {0xff0000, 0x00ff00, 0x0000ff}, null), op); } }
Example 15
Source File: ChartTransferable.java From buffer_bci with GNU General Public License v3.0 | 4 votes |
/** * A utility method that creates an image of a chart, with scaling. * * @param chart the chart. * @param w the image width. * @param h the image height. * @param minDrawW the minimum width for chart drawing. * @param minDrawH the minimum height for chart drawing. * @param maxDrawW the maximum width for chart drawing. * @param maxDrawH the maximum height for chart drawing. * * @return A chart image. * * @since 1.0.14 */ private BufferedImage createBufferedImage(JFreeChart chart, int w, int h, int minDrawW, int minDrawH, int maxDrawW, int maxDrawH) { BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = image.createGraphics(); // work out if scaling is required... boolean scale = false; double drawWidth = w; double drawHeight = h; double scaleX = 1.0; double scaleY = 1.0; if (drawWidth < minDrawW) { scaleX = drawWidth / minDrawW; drawWidth = minDrawW; scale = true; } else if (drawWidth > maxDrawW) { scaleX = drawWidth / maxDrawW; drawWidth = maxDrawW; scale = true; } if (drawHeight < minDrawH) { scaleY = drawHeight / minDrawH; drawHeight = minDrawH; scale = true; } else if (drawHeight > maxDrawH) { scaleY = drawHeight / maxDrawH; drawHeight = maxDrawH; scale = true; } Rectangle2D chartArea = new Rectangle2D.Double(0.0, 0.0, drawWidth, drawHeight); if (scale) { AffineTransform st = AffineTransform.getScaleInstance(scaleX, scaleY); g2.transform(st); } chart.draw(g2, chartArea, null, null); g2.dispose(); return image; }
Example 16
Source File: IncorrectClipXorModeSW2Surface.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public static void main(final String[] args) throws IOException { GraphicsEnvironment ge = GraphicsEnvironment .getLocalGraphicsEnvironment(); GraphicsConfiguration gc = ge.getDefaultScreenDevice() .getDefaultConfiguration(); AffineTransform at; for (int size : SIZES) { at = AffineTransform.getScaleInstance(size, size); for (Shape clip : SHAPES) { clip = at.createTransformedShape(clip); for (Shape to : SHAPES) { to = at.createTransformedShape(to); // Prepare test images BufferedImage snapshot; BufferedImage bi = getBufferedImage(size); VolatileImage vi = getVolatileImage(gc, size); while (true) { vi.validate(gc); Graphics2D g2d = vi.createGraphics(); g2d.setColor(Color.GREEN); g2d.fillRect(0, 0, size, size); g2d.dispose(); if (vi.validate(gc) != VolatileImage.IMAGE_OK) { continue; } draw(clip, to, bi, vi); snapshot = vi.getSnapshot(); if (vi.contentsLost()) { continue; } break; } // Prepare gold images BufferedImage goldvi = getCompatibleImage(gc, size); BufferedImage goldbi = getBufferedImage(size); draw(clip, to, goldbi, goldvi); validate(snapshot, goldvi); vi.flush(); } } } }
Example 17
Source File: IncorrectClipXorModeSurface2Surface.java From hottub with GNU General Public License v2.0 | 4 votes |
public static void main(final String[] args) throws IOException { GraphicsEnvironment ge = GraphicsEnvironment .getLocalGraphicsEnvironment(); GraphicsConfiguration gc = ge.getDefaultScreenDevice() .getDefaultConfiguration(); AffineTransform at; for (int size : SIZES) { at = AffineTransform.getScaleInstance(size, size); for (Shape clip : SHAPES) { clip = at.createTransformedShape(clip); for (Shape to : SHAPES) { to = at.createTransformedShape(to); // Prepare test images BufferedImage snapshot; VolatileImage source = getVolatileImage(gc, size); VolatileImage target = getVolatileImage(gc, size); int attempt = 0; while (true) { if (++attempt > 10) { throw new RuntimeException("Too many attempts: " + attempt); } // Prepare source images source.validate(gc); Graphics2D g2d = source.createGraphics(); g2d.setColor(Color.RED); g2d.fillRect(0, 0, size, size); g2d.dispose(); if (source.validate(gc) != VolatileImage.IMAGE_OK) { continue; } // Prepare target images target.validate(gc); g2d = target.createGraphics(); g2d.setColor(Color.GREEN); g2d.fillRect(0, 0, size, size); g2d.dispose(); if (target.validate(gc) != VolatileImage.IMAGE_OK) { continue; } draw(clip, to, source, target); snapshot = target.getSnapshot(); if (source.contentsLost() || target.contentsLost()) { continue; } break; } // Prepare gold images BufferedImage goldS = getSourceGold(gc, size); BufferedImage goldT = getTargetGold(gc, size); draw(clip, to, goldS, goldT); validate(snapshot, goldT); source.flush(); target.flush(); } } } }
Example 18
Source File: RenderableImageOp.java From TencentKona-8 with GNU General Public License v2.0 | 3 votes |
/** * Creates a RenderedImage instance of this image with width w, and * height h in pixels. The RenderContext is built automatically * with an appropriate usr2dev transform and an area of interest * of the full image. All the rendering hints come from hints * passed in. * * <p> If w == 0, it will be taken to equal * Math.round(h*(getWidth()/getHeight())). * Similarly, if h == 0, it will be taken to equal * Math.round(w*(getHeight()/getWidth())). One of * w or h must be non-zero or else an IllegalArgumentException * will be thrown. * * <p> The created RenderedImage may have a property identified * by the String HINTS_OBSERVED to indicate which RenderingHints * were used to create the image. In addition any RenderedImages * that are obtained via the getSources() method on the created * RenderedImage may have such a property. * * @param w the width of rendered image in pixels, or 0. * @param h the height of rendered image in pixels, or 0. * @param hints a RenderingHints object containing hints. * @return a RenderedImage containing the rendered data. */ public RenderedImage createScaledRendering(int w, int h, RenderingHints hints) { // DSR -- code to try to get a unit scale double sx = (double)w/getWidth(); double sy = (double)h/getHeight(); if (Math.abs(sx/sy - 1.0) < 0.01) { sx = sy; } AffineTransform usr2dev = AffineTransform.getScaleInstance(sx, sy); RenderContext newRC = new RenderContext(usr2dev, hints); return createRendering(newRC); }
Example 19
Source File: RenderableImageOp.java From jdk8u-jdk with GNU General Public License v2.0 | 3 votes |
/** * Creates a RenderedImage instance of this image with width w, and * height h in pixels. The RenderContext is built automatically * with an appropriate usr2dev transform and an area of interest * of the full image. All the rendering hints come from hints * passed in. * * <p> If w == 0, it will be taken to equal * Math.round(h*(getWidth()/getHeight())). * Similarly, if h == 0, it will be taken to equal * Math.round(w*(getHeight()/getWidth())). One of * w or h must be non-zero or else an IllegalArgumentException * will be thrown. * * <p> The created RenderedImage may have a property identified * by the String HINTS_OBSERVED to indicate which RenderingHints * were used to create the image. In addition any RenderedImages * that are obtained via the getSources() method on the created * RenderedImage may have such a property. * * @param w the width of rendered image in pixels, or 0. * @param h the height of rendered image in pixels, or 0. * @param hints a RenderingHints object containing hints. * @return a RenderedImage containing the rendered data. */ public RenderedImage createScaledRendering(int w, int h, RenderingHints hints) { // DSR -- code to try to get a unit scale double sx = (double)w/getWidth(); double sy = (double)h/getHeight(); if (Math.abs(sx/sy - 1.0) < 0.01) { sx = sy; } AffineTransform usr2dev = AffineTransform.getScaleInstance(sx, sy); RenderContext newRC = new RenderContext(usr2dev, hints); return createRendering(newRC); }
Example 20
Source File: AvatarChooser.java From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License | votes |
private BufferedImage createReflection(BufferedImage avatar, int avatarWidth, int avatarHeight) { BufferedImage buffer = new BufferedImage(avatarWidth, avatarHeight << 1, BufferedImage.TYPE_INT_ARGB); Graphics2D g = buffer.createGraphics(); g.drawImage(avatar, null, null); g.translate(0, avatarHeight << 1); AffineTransform reflectTransform = AffineTransform.getScaleInstance(1.0, -1.0); g.drawImage(avatar, reflectTransform, null); g.translate(0, -(avatarHeight << 1)); g.dispose(); return buffer; }