List of usage examples for java.awt.geom Area Area
public Area(Shape s)
From source file:Main.java
public static void main(String[] args) { Area shape = new Area(new Rectangle(1, 1, 1, 1)); shape.add(new Area(new Rectangle(1, 1, 1, 1))); shape.subtract(new Area(new Rectangle(1, 1, 1, 1))); shape.intersect(new Area(new Rectangle(1, 1, 1, 1))); shape.exclusiveOr(new Area(new Rectangle(1, 1, 1, 1))); System.out.println(shape.intersects(new Rectangle(1, 1, 1, 1))); }
From source file:BasicShapes.java
public static void main(String[] args) { Area shape = new Area(new Rectangle(1, 1, 1, 1)); shape.add(new Area(new Rectangle(1, 1, 1, 1))); shape.subtract(new Area(new Rectangle(1, 1, 1, 1))); shape.intersect(new Area(new Rectangle(1, 1, 1, 1))); shape.exclusiveOr(new Area(new Rectangle(1, 1, 1, 1))); }
From source file:Main.java
public static void main(String[] args) throws Exception { URL url = new URL("http://www.java2s.com/style/download.png"); BufferedImage image = ImageIO.read(url); int w = image.getWidth(); int h = image.getHeight(); Ellipse2D.Double ellipse1 = new Ellipse2D.Double(10, 10, 20, 30); Ellipse2D.Double ellipse2 = new Ellipse2D.Double(15, 15, 20, 30); Area circle = new Area(ellipse1); circle.subtract(new Area(ellipse2)); BufferedImage result = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g = result.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 . j a v a 2 s . com g.drawImage(image, 0, 0, null); g.dispose(); ImageIO.write(result, "png", new File("result.png")); }
From source file:G2DCircleIntersectPDF.java
public static void main(String[] args) { Document document = new Document(); try {//from ww w . ja va 2 s. c o m PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("G2DCircleIntersectPDF.pdf")); document.open(); DefaultFontMapper mapper = new DefaultFontMapper(); FontFactory.registerDirectories(); mapper.insertDirectory("c:\\windows\\fonts"); int w = 150; int h = 150; PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(w, h); Graphics2D g2 = tp.createGraphics(w, h, mapper); tp.setWidth(w); tp.setHeight(h); double ew = w / 2; double eh = h / 2; Ellipse2D.Double circle, circle1; circle = new Ellipse2D.Double(ew - 16, eh - 29, 50.0, 50.0); g2.setColor(Color.green); g2.fill(circle); g2.setColor(Color.red); circle1 = new Ellipse2D.Double(ew, eh, 50.0, 50.0); g2.fill(circle1); Area area1 = new Area(circle); Area area2 = new Area(circle1); g2.setColor(Color.BLUE); area1.intersect(area2); g2.fill(area1); g2.dispose(); cb.addTemplate(tp, 50, 400); } catch (Exception e) { System.err.println(e.getMessage()); } document.close(); }
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 ww w . j a va 2s . 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:Main.java
public static Area getArrowFromTo(Point2D.Double from, Point2D.Double to) { double dx = 8; double dy = Math.floor(dx / 2); if (from.getX() < to.getX()) dx *= -1;/*w w w . j av a 2 s .c o m*/ GeneralPath arrowHeadFrom = new GeneralPath(); arrowHeadFrom.moveTo(to.getX() + dx, to.getY() - dy); arrowHeadFrom.lineTo(to.getX(), to.getY()); arrowHeadFrom.lineTo(to.getX() + dx, to.getY() + dy); arrowHeadFrom.lineTo(to.getX() + dx, to.getY() + 0.1); arrowHeadFrom.lineTo(from.getX(), from.getY() + 0.1); arrowHeadFrom.lineTo(from.getX(), from.getY() - 0.1); arrowHeadFrom.lineTo(to.getX() + dx, to.getY() - 0.1); arrowHeadFrom.lineTo(to.getX() + dx, to.getY() - dy); Area b = new Area(arrowHeadFrom); return b; }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Ellipse2D e1 = new Ellipse2D.Double(20.0, 20.0, 80.0, 70.0); Ellipse2D e2 = new Ellipse2D.Double(20.0, 70.0, 40.0, 40.0); Area a1 = new Area(e1); Area a2 = new Area(e2); a1.add(a2);/*from www. j a v a2 s . c o m*/ g2.setColor(Color.orange); g2.fill(a1); }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Ellipse2D e1 = new Ellipse2D.Double(20.0, 20.0, 80.0, 70.0); Ellipse2D e2 = new Ellipse2D.Double(20.0, 70.0, 40.0, 40.0); Area a1 = new Area(e1); Area a2 = new Area(e2); a1.exclusiveOr(a2);//w w w . j a v a2s . c om g2.setColor(Color.orange); g2.fill(a1); g2.setColor(Color.black); g2.drawString("exclusiveOr", 20, 140); }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Ellipse2D e1 = new Ellipse2D.Double(20.0, 20.0, 80.0, 70.0); Ellipse2D e2 = new Ellipse2D.Double(20.0, 70.0, 40.0, 40.0); Area a1 = new Area(e1); Area a2 = new Area(e2); a1.intersects(20, 20, 300, 300);/*from www . j ava 2s.c o m*/ g2.setColor(Color.orange); g2.fill(a1); g2.setColor(Color.black); g2.drawString("intersect", 20, 140); }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Ellipse2D e1 = new Ellipse2D.Double(20.0, 20.0, 80.0, 70.0); Ellipse2D e2 = new Ellipse2D.Double(20.0, 70.0, 40.0, 40.0); Area a1 = new Area(e1); Area a2 = new Area(e2); a1.subtract(a2);// ww w . jav a 2 s . c om g2.setColor(Color.orange); g2.fill(a1); g2.setColor(Color.black); g2.drawString("subtract", 20, 140); System.out.println(a1.contains(50, 50, 5, 5)); }