Refine search
destination = new BufferedImage((int) w, (int) h, BufferedImage.TYPE_INT_ARGB); final Graphics2D gg = destination.createGraphics(); gg.scale(dpiFactor, dpiFactor); gg.translate(deltaShadow - bounds.getMinX(), deltaShadow - bounds.getMinY()); final boolean isLine = shape instanceof Line2D.Double; if (isLine) { gg.fill(shape); gg.dispose(); g2d.scale(1 / dpiFactor, 1 / dpiFactor); g2d.drawImage(destination, (int) (bounds.getMinX() * dpiFactor), (int) (bounds.getMinY() * dpiFactor), null); g2d.setTransform(at);
private BufferedImage renderGlyph(GeneralPath path, Rectangle2D bounds2D, Rectangle cellRect) { BufferedImage bim = new BufferedImage((int) cellRect.getWidth(), (int) cellRect.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics2D g = (Graphics2D) bim.getGraphics(); g.setBackground(Color.white); g.clearRect(0, 0, bim.getWidth(), bim.getHeight()); double scale = 1 / ((yBounds[1] - yBounds[0]) / cellRect.getHeight()); // flip g.scale(1, -1); g.translate(0, -bim.getHeight()); // horizontal center g.translate((cellRect.getWidth() - bounds2D.getWidth() * scale) / 2, 0); // scale from the glyph to the cell g.scale(scale, scale); // Adjust for negative y min bound g.translate(0, -yBounds[0]); g.setColor(Color.black); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.fill(path); g.dispose(); return bim; } }
final double ax = anchor.getX(); final double ay = anchor.getY(); graphics.translate(ax + anchor.getWidth(), ay); graphics.scale(-1, 1); graphics.translate(-ax, -ay); final double cx = anchor.getCenterX(); final double cy = anchor.getCenterY(); graphics.translate(cx, cy); graphics.rotate(Math.toRadians(textRot)); graphics.translate(-cx, -cy);
public class MyExtendedClass extends ... { @Override public void paint(Graphics g) { Graphics2D g2d = (Graphics2D)g.create(); double scaleFactor = 1d; // Calculate the scaling factor to apply // based on the "default" size and the // current size... g2d.scale(scaleFactor, scaleFactor); super.paint(g2d); g2d.dispose(); } }
@Override public void drawParticlesWireframe(Vec2[] centers, float radius, ParticleColor[] colors, int count) { Graphics2D g = getGraphics(); saveState(g); transformGraphics(g, zero); g.setStroke(stroke); for (int i = 0; i < count; i++) { Vec2 center = centers[i]; Color color; // No alpha channel, it slows everything down way too much. if (colors == null) { color = pcolor; } else { ParticleColor c = colors[i]; color = new Color(c.r * 1f / 127, c.g * 1f / 127, c.b * 1f / 127, 1); } AffineTransform old = g.getTransform(); g.translate(center.x, center.y); g.scale(radius, radius); g.setColor(color); g.draw(circle); g.setTransform(old); } restoreState(g); }