List of usage examples for java.awt Graphics2D setColor
public abstract void setColor(Color c);
From source file:Main.java
@Override protected void paintComponent(Graphics window) { super.paintComponent(window); Graphics2D twoDGraph = (Graphics2D) window; if (time % 2 == 0) { twoDGraph.setColor(Color.RED); } else {/*from w ww . j a va 2s.c om*/ twoDGraph.setColor(Color.GREEN); } twoDGraph.fillOval(100, 100, 600, 600); time++; }
From source file:FontHints.java
protected void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setColor(Color.WHITE); g2d.fillRect(0, 0, getWidth(), getHeight()); g2d.setColor(Color.BLACK);// w w w . ja va2s .c o m g2d.drawString("Unhinted string", 10, 20); if (desktopHints != null) { g2d.addRenderingHints(desktopHints); } g2d.drawString("Desktop-hinted string", 10, 40); }
From source file:BasicShapes.java
public void paint(Graphics g) { BufferedImage bimage = new BufferedImage(200, 200, BufferedImage.TYPE_BYTE_INDEXED); Graphics2D g2d = bimage.createGraphics(); Color transparent = new Color(0, 0, 0, 0); g2d.setColor(transparent); g2d.setComposite(AlphaComposite.Src); g2d.fill(new Rectangle2D.Float(20, 20, 100, 20)); g2d.dispose();/* ww w . jav a 2 s . c o m*/ }
From source file:TextureWithBufferedImage.java
public void paint(Graphics g) { Graphics2D g2D = (Graphics2D) g; Rectangle2D rec1, rec2, rec3, rec4, rec5; rec1 = new Rectangle2D.Float(25, 25, 75, 150); rec2 = new Rectangle2D.Float(125, 25, 10, 75); rec3 = new Rectangle2D.Float(75, 125, 125, 75); rec4 = new Rectangle2D.Float(25, 15, 12, 75); rec5 = new Rectangle2D.Float(15, 50, 15, 15); AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1); g2D.setComposite(ac);//from w w w. ja v a 2 s . c o m g2D.setStroke(new BasicStroke(5.0f)); g2D.draw(rec1); GradientPaint gp = new GradientPaint(125f, 25f, Color.yellow, 225f, 100f, Color.blue); g2D.setPaint(gp); g2D.fill(rec2); BufferedImage bi = new BufferedImage(5, 5, BufferedImage.TYPE_INT_RGB); Graphics2D big = bi.createGraphics(); big.setColor(Color.magenta); big.fillRect(0, 0, 5, 5); big.setColor(Color.black); big.drawLine(0, 0, 5, 5); Rectangle r = new Rectangle(0, 0, 5, 5); TexturePaint tp = new TexturePaint(bi, r); g2D.setPaint(tp); g2D.fill(rec3); g2D.setColor(Color.green); g2D.fill(rec4); g2D.setColor(Color.red); g2D.fill(rec5); }
From source file:MainClass.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Ellipse2D e1 = new Ellipse2D.Double(20.0, 20.0, 80.0, 70.0); g2.setColor(Color.red); g2.fill(e1);// w ww . j a v a 2 s . c o m }
From source file:nl.b3p.viewer.image.ImageTool.java
public static BufferedImage drawGeometries(BufferedImage bi, CombineImageSettings settings, int srid, Bbox bbox, int width, int height) throws Exception { List wktGeoms = settings.getWktGeoms(); if (wktGeoms == null || wktGeoms.size() <= 0) { return bi; }//from ww w . j ava2 s.co m BufferedImage newBufIm = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE); // BufferedImage newBufIm = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D gbi = newBufIm.createGraphics(); gbi.drawImage(bi, 0, 0, null); for (int i = 0; i < wktGeoms.size(); i++) { gbi.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); CombineImageWkt ciw = (CombineImageWkt) wktGeoms.get(i); Color color = settings.getDefaultWktGeomColor(); if (ciw.getColor() != null) { color = ciw.getColor(); } gbi.setColor(color); String wktGeom = ciw.getWktGeom(); Geometry geom = geometrieFromText(wktGeom, srid); Shape shape = createImage(geom, srid, bbox, width, height); Point centerPoint = null; if (geom instanceof Polygon) { gbi.fill(shape); } else if (geom instanceof com.vividsolutions.jts.geom.Point) { centerPoint = calculateCenter(shape, srid, bbox, width, height); gbi.fill(new Ellipse2D.Double(centerPoint.getX(), centerPoint.getY(), 8, 8)); } else { float strokeWidth = ciw.getStrokeWidth() != null ? ciw.getStrokeWidth() : 3f; gbi.setStroke(new BasicStroke(strokeWidth)); gbi.draw(shape); } if (ciw.getLabel() != null) { if (centerPoint == null) { centerPoint = calculateCenter(shape, srid, bbox, width, height); } gbi.setColor(Color.black); gbi.drawString(ciw.getLabel(), (float) centerPoint.getX(), (float) centerPoint.getY()); } } gbi.dispose(); return newBufIm; }
From source file:BezLab.java
public void paint(Graphics g) { for (int i = 0; i < 4; i++) { if (i == 0 || i == 3) g.setColor(Color.blue); else//from ww w.j av a2 s. co m g.setColor(Color.cyan); g.fillOval(xs[i] - 6, ys[i] - 6, 12, 12); } Graphics2D g2d = (Graphics2D) g; g2d.setColor(Color.black); GeneralPath path = new GeneralPath(); path.moveTo(xs[0], ys[0]); path.curveTo(xs[1], ys[1], xs[2], ys[2], xs[3], ys[3]); g2d.draw(path); }
From source file:com.liud.dailynote.ThumbnailatorTest.java
public void testYS7() throws IOException { String result = "src/main/resources/images/"; BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); Graphics2D g = bi.createGraphics(); g.setColor(Color.LIGHT_GRAY); g.drawRect(0, 0, 10, 10);/*from w w w . j a v a 2 s . co m*/ char[] data = "liudTest".toCharArray(); g.drawChars(data, 0, data.length, 5, 32); // watermark ? 1.? 2.? 3.? Thumbnails.of(result + "sijili.jpg").scale(1.0f).watermark(Positions.CENTER, bi, 1.0f) .toFile(result + "image_warter_liud.jpg"); }
From source file:Main.java
public void repaint(BufferedImage orig, BufferedImage copy) { Graphics2D g = copy.createGraphics(); g.drawImage(orig, 0, 0, null);//from w w w .j a v a 2 s. c o m g.setColor(Color.RED); if (captureRect == null) { return; } g.draw(captureRect); g.setColor(new Color(25, 25, 23, 10)); g.fill(captureRect); g.dispose(); }
From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java
public static void drawText(Graphics2D g2, Rectangle2D imageArea, LinkedHashMap<Rectangle2D, String> textContentMap, JFreeChart chart) { if (textContentMap == null || textContentMap.size() == 0) { return;//from ww w . j a va2 s . c o m } // for (Entry<Rectangle2D, String> textEntry : textMap.entrySet()) { // Rectangle2D rect = textEntry.getKey(); // String text = textEntry.getValue(); // drawText(g2, imageArea, rect, text, chart); // } Color oldColor = g2.getColor(); g2.setColor(Color.BLACK); for (Entry<Rectangle2D, String> entry : textContentMap.entrySet()) { Rectangle2D rect = entry.getKey(); Point2D screenPoint = ChartMaskingUtilities .translateChartPoint(new Point2D.Double(rect.getX(), rect.getY()), imageArea, chart); String text = entry.getValue(); if (text == null) { continue; } String[] lines = text.split("\n"); g2.setColor(Color.BLACK); for (int i = 0; i < lines.length; i++) { g2.drawString(lines[i], (int) screenPoint.getX() + 3, (int) screenPoint.getY() - 3 + i * 15); } // if (rect == selectedTextWrapper) { // FontMetrics fm = g2.getFontMetrics(); // int maxWidth = 0; // int maxHeight = 0; // for (int i = 0; i < lines.length; i++) { // int lineWidth = fm.stringWidth(lines[i]); // if (lineWidth > maxWidth) { // maxWidth = lineWidth; // } // } // maxHeight = 15 * lines.length; // if (maxWidth < 100) { // maxWidth = 100; // } // Rectangle2D inputBox = new Rectangle2D.Double(screenPoint.getX(), screenPoint.getY() - 15, maxWidth + 8, maxHeight); // Color fillColor = new Color(250, 250, 50, 30); // g2.setPaint(fillColor); // g2.fill(inputBox); // g2.setColor(Color.ORANGE); // g2.drawRect((int) screenPoint.getX(), (int) screenPoint.getY() - 15, maxWidth + 8, maxHeight); // // } // g2.drawString(text == null ? "" : text, (int) screenPoint.getX() + 3, (int) screenPoint.getY() - 3); } g2.setColor(oldColor); }