Example usage for java.awt Graphics2D draw

List of usage examples for java.awt Graphics2D draw

Introduction

In this page you can find the example usage for java.awt Graphics2D draw.

Prototype

public abstract void draw(Shape s);

Source Link

Document

Strokes the outline of a Shape using the settings of the current Graphics2D context.

Usage

From source file:org.jfree.graphics2d.demo.ImageTest.java

private static void drawArcTest(Graphics2D g2) {
    g2.setPaint(Color.GREEN);/*from  w ww . j av  a 2s . co m*/
    g2.drawRect(0, 20, 70, 50);
    g2.setPaint(Color.RED);
    Path2D path1 = new Path2D.Double();
    double[] pts = calculateReferenceArc(90);
    path1.moveTo(pts[0], pts[1]);
    path1.curveTo(pts[2], pts[3], pts[4], pts[5], pts[6], pts[7]);
    AffineTransform t = new AffineTransform();
    t.translate(35, 45);
    t.scale(35, 25);
    t.rotate(Math.PI / 4);
    path1.transform(t);
    g2.draw(path1);

    Path2D path2 = new Path2D.Double();
    path2.moveTo(pts[0], pts[1]);
    path2.curveTo(pts[2], pts[3], pts[4], pts[5], pts[6], pts[7]);
    AffineTransform t2 = new AffineTransform();
    t2.rotate(3 * Math.PI / 4);
    t2.scale(35, 25);
    t2.translate(35, 35);
    path2.transform(t2);
    //g2.draw(path2);
    Path2D arc = new Path2D.Double();
    arc.append(path1, false);
    arc.append(path2, false);
    //g2.draw(arc);
    //g2.draw(path1);
    //g2.transform(t);
    g2.setPaint(Color.BLUE);
    g2.drawArc(0, 20, 70, 50, 0, -270);
    //Arc2D arc2d = new Arc2D.Double(0d, 20d, 70d, 50d, 0d, 90, Arc2D.OPEN);
    //g2.draw(arc2d);
}

From source file:Main.java

public static void draw(BufferedImage imageBG, BufferedImage imageFG) {
    Ellipse2D.Double ellipse1 = new Ellipse2D.Double(20, 20, 30, 30);
    Ellipse2D.Double ellipse2 = new Ellipse2D.Double(25, 25, 30, 30);
    Area circle = new Area(ellipse1);
    circle.subtract(new Area(ellipse2));

    Graphics2D g = imageBG.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
    g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g.setClip(circle);//from w  w w  .  ja  v  a2s  .c  o m
    g.drawImage(imageFG, 0, 0, null);
    g.setClip(null);
    Stroke s = new BasicStroke(2);
    g.setStroke(s);
    g.setColor(Color.BLACK);
    g.draw(circle);
    g.dispose();

    JLabel l = new JLabel(new ImageIcon(imageBG));
    JOptionPane.showMessageDialog(null, l);
}

From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java

public static void drawMaskBoarder(Graphics2D g2, Rectangle2D frame) {
    g2.setPaint(Color.orange);//from ww  w.  j  av a2  s  . c  o  m
    g2.setStroke(new BasicStroke(1));
    g2.draw(frame);
    Rectangle2D dragPoint = new Rectangle2D.Double(frame.getMinX() - maskDragPointHalfWidth,
            frame.getMinY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getCenterX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getCenterY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMinX() - maskDragPointHalfWidth, frame.getCenterY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMinX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getCenterX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    Color fillColor = new Color(250, 250, 50, 30);
    g2.setPaint(fillColor);
    g2.fill(frame);
}

From source file:org.springframework.cloud.stream.app.pose.estimation.processor.DebugVisualizationUtility.java

private static byte[] drawPafField(byte[] imageBytes, Model.LimbType limbType, float[][][] outputTensor,
        Color color) {/*from   w  w w . j  a  v  a  2 s. c om*/

    return new ImageGraphicsTemplate() {
        @Override
        public void drawWithingImage(Graphics2D g) {
            g.setColor(color);
            for (int x = 0; x < outputTensor.length; x++) {
                for (int y = 0; y < outputTensor[0].length; y++) {
                    float pafX = outputTensor[x][y][limbType.getPafIndexX()];
                    float pafY = outputTensor[x][y][limbType.getPafIndexY()];

                    if (pafX > 0.1f || pafY > 0.1f) {
                        g.draw(new Line2D.Double(y * 8, x * 8, (y + 2 * pafY) * 8, (x + 3 * pafX) * 8));
                    }

                }
            }
        }
    }.draw(imageBytes);
}

From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java

private static void drawMaskBoarder(Graphics2D g2, Abstract2DMask mask) {
    g2.setPaint(Color.orange);/*from w w w  . ja v  a  2s. c o m*/
    g2.setStroke(new BasicStroke(1));
    Rectangle2D frame = mask.getRectangleFrame();
    g2.draw(frame);
    Rectangle2D dragPoint = new Rectangle2D.Double(frame.getMinX() - maskDragPointHalfWidth,
            frame.getMinY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getCenterX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getCenterY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMinX() - maskDragPointHalfWidth, frame.getCenterY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMinX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getCenterX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    Color fillColor = new Color(250, 250, 50, 10);
    g2.setPaint(fillColor);
    g2.fill(mask.getShape());
}

From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java

public static void drawShape(Graphics2D g2, Rectangle2D imageArea, Shape shape, Color color, JFreeChart chart) {
    g2.clip(imageArea);/*from   w w  w.j  a va 2 s  . co m*/
    g2.setPaint(color);
    Shape newShape = translateChartShape(shape, imageArea, chart);
    if (shape == null) {
        return;
    }
    g2.draw(newShape);
}

From source file:Hexagon.java

public static File write(String fileName, Shape shape) throws IOException {
    Rectangle bounds = shape.getBounds();
    BufferedImage img = createImage(bounds.width, bounds.height);
    Graphics2D g2 = (Graphics2D) img.createGraphics();
    //g2.setColor(WebColor.CornSilk.getColor());
    g2.fill(shape);/*from  w w w.  j av a 2 s. co m*/
    g2.setColor(Color.black);
    g2.draw(shape);
    return write(fileName, img);
}

From source file:org.springframework.cloud.stream.app.pose.estimation.processor.DebugVisualizationUtility.java

private static byte[] drawLimbCandidate(byte[] imageBytes, Limb limb) {

    return new ImageGraphicsTemplate() {
        @Override//from   w w  w .ja va  2 s . c o  m
        public void drawWithingImage(Graphics2D g) {
            Part from = limb.getFromPart();
            Part to = limb.getToPart();

            int x1 = from.getNormalizedX();
            int x2 = to.getNormalizedX();

            int y1 = from.getNormalizedY();
            int y2 = to.getNormalizedY();

            int xl = (x2 - x1) / 2;
            int yl = (y2 - y1) / 2;

            g.setColor(GraphicsUtils.yellow);
            g.drawString(String.format("%.2f", limb.getPafScore()), x1 + xl + 5, y1 + yl + 5);

            g.setColor(new Color(167, 252, 0));
            g.draw(new Line2D.Double(from.getNormalizedX(), from.getNormalizedY(), to.getNormalizedX(),
                    to.getNormalizedY()));

            g.setColor(GraphicsUtils.CLASS_COLOR2[from.getPartType().getId()]);
            g.fillOval(from.getNormalizedX() - OVAL_WIDTH / 2, from.getNormalizedY() - OVAL_WIDTH / 2,
                    OVAL_WIDTH, OVAL_HEIGHT);
            g.setColor(GraphicsUtils.CLASS_COLOR2[to.getPartType().getId()]);
            g.fillOval(to.getNormalizedX() - OVAL_WIDTH / 2, to.getNormalizedY() - OVAL_WIDTH / 2, OVAL_WIDTH,
                    OVAL_HEIGHT);
        }
    }.draw(imageBytes);
}

From source file:org.mabb.fontverter.opentype.DebugGlyphDrawer.java

public static void drawGlyph(TtfGlyph glyph) throws IOException {
    BufferedImage image = new BufferedImage(650, 650, BufferedImage.TYPE_INT_RGB);
    Graphics2D gfx = image.createGraphics();

    gfx.translate(0, 300);//from   w w  w .  j  ava2s .  c  o  m
    gfx.scale(1, -1);

    gfx.setColor(Color.white);
    gfx.fillRect(0, -1000, 2060, 2060);
    gfx.setColor(Color.lightGray);
    gfx.translate(100, 50);
    gfx.fillRect(0, 0, 1000, 1000);
    gfx.setColor(Color.BLACK);

    gfx.scale(.05, .05);

    //        gfx.rotate(Math.toRadians(180));
    //        gfx.translate(-2200, -2200);

    Color[] colors = new Color[] { Color.BLACK, Color.MAGENTA, Color.GREEN, Color.BLUE, Color.cyan };
    java.util.List<Path2D.Double> paths = glyph.getPaths();
    for (int i = 0; i < paths.size(); i++) {
        Path2D pathOn = paths.get(i);
        gfx.setColor(colors[i]);

        gfx.draw(pathOn);
    }

    gfx.dispose();

    //        ImageIO.write(image, "jpg", new File("test.jpg"));
}

From source file:Main.java

License:asdf

public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.draw(getTextShape(g2d, "asdf", new Font("", 1, 30)));
}