public static BufferedImage makeRoundedCorner(BufferedImage image, int cornerRadius) { int w = image.getWidth(); int h = image.getHeight(); BufferedImage output = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = output.createGraphics(); // This is what we want, but it only does hard-clipping, i.e. aliasing // g2.setClip(new RoundRectangle2D ...) // so instead fake soft-clipping by first drawing the desired clip shape // in fully opaque white with antialiasing enabled... g2.setComposite(AlphaComposite.Src); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.WHITE); g2.fill(new RoundRectangle2D.Float(0, 0, w, h, cornerRadius, cornerRadius)); // ... then compositing the image on top, // using the white shape from above as alpha source g2.setComposite(AlphaComposite.SrcAtop); g2.drawImage(image, 0, 0, null); g2.dispose(); return output; }
public static BufferedImage getRoundCorner(BufferedImage image) { if (image != null) { BufferedImage cornerImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB); // corner float ROUNDED_CORNER_SIZE = 0.11f; // see CardPanelComponentImpl int cornerSizeBorder = Math.max(4, Math.round(image.getWidth() * ROUNDED_CORNER_SIZE)); // corner mask Graphics2D gg = cornerImage.createGraphics(); gg.setComposite(AlphaComposite.Src); gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); gg.setColor(Color.white); gg.fill(new RoundRectangle2D.Float(0, 0, cornerImage.getWidth(), cornerImage.getHeight(), cornerSizeBorder, cornerSizeBorder)); // image draw to buffer gg.setComposite(AlphaComposite.SrcAtop); gg.drawImage(image, 0, 0, null); gg.dispose(); return cornerImage; } else { return image; } }
public static BufferedImage makeRoundedCorner(BufferedImage image, int cornerRadius, int borderWidth) { if ((float) cornerRadius == 0) return image; int w = image.getWidth(); int h = image.getHeight(); BufferedImage output = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); //BufferedImage output = UIUtil.createImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = output.createGraphics(); // This is what we want, but it only does hard-clipping, i.e. aliasing // g2.setClip(new RoundRectangle2D ...) // so instead fake soft-clipping by first drawing the desired clip shape // in fully opaque white with antialiasing enabled... g2.setComposite(AlphaComposite.Src); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.WHITE); g2.fill(new RoundRectangle2D.Float(0, 0, w, h, (float) cornerRadius, (float) cornerRadius)); // ... then compositing the image on top, // using the white shape from above as alpha source g2.setComposite(AlphaComposite.SrcAtop); g2.drawImage(image, 0, 0, null); g2.dispose(); //output.setRGB(3, 3, 123); return output; }
private void calculateShape() { float arcwh = width * roundness; Shape beam1 = new RoundRectangle2D.Float( cx - radius, cy - (width / 2), radius * 2, width, arcwh, arcwh ); Shape beam2 = new RoundRectangle2D.Float( cx - (width / 2), cy - radius, width, radius * 2, arcwh, arcwh ); cross = new Area( beam1 ); ((Area) cross).add( new Area( beam2 ) ); cross = ShapeUtils.rotate( cross, angle, cx, cy ); } }
private RoundRectangle2D.Float hazBoton( JComponent c) { RoundRectangle2D.Float boton = new RoundRectangle2D.Float(); boton.x = 0; boton.y = 0; boton.width = c.getWidth(); boton.height = c.getHeight(); boton.arcwidth = 8; boton.archeight = 8; return boton; }
public java.awt.Shape getOutline(Shape shape){ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400); RoundRectangle2D path = new RoundRectangle2D.Float(0, 0, 21600, 21600, adjval, adjval); return path; } };
public void paint (Graphics g) { Graphics2D gr = (Graphics2D) g; Shape previousClip = gr.getClip (); gr.clip (new RoundRectangle2D.Float (0, 0, getWidth (), getHeight (), 8, 8)); super.paint (g); gr.setClip (previousClip); }
@Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); RoundRectangle2D roundedRectangle = new RoundRectangle2D.Float(0, 0, getWidth(), getHeight(), 15, 15); g2d.fill(roundedRectangle); } }
public void paint (Graphics2D gr, Rectangle bounds) { if (fillColor != null) { gr.setColor (fillColor); gr.fill (new RoundRectangle2D.Float (bounds.x, bounds.y, bounds.width, bounds.height, arcWidth, arcHeight)); } if (drawColor != null) { gr.setColor (drawColor); gr.draw (new RoundRectangle2D.Float (bounds.x + 0.5f, bounds.y + 0.5f, bounds.width - 1, bounds.height - 1, arcWidth, arcHeight)); } }
/** Always returns null for rectangular Roi's */ public ImageProcessor getMask() { if (cornerDiameter>0) return (new ShapeRoi(new RoundRectangle2D.Float(x, y, width, height, cornerDiameter, cornerDiameter))).getMask(); else return null; }
private RoundRectangle2D roundRect = new RoundRectangle2D.Float(0, 0, 0, 0, 0, 0); private Ellipse2D ellipse = new Ellipse2D.Float(0, 0, 0, 0);
private RoundRectangle2D roundRect = new RoundRectangle2D.Float(0, 0, 0, 0, 0, 0); private Ellipse2D ellipse = new Ellipse2D.Float(0, 0, 0, 0);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int r = 5; RoundRectangle2D round = new RoundRectangle2D.Float(x, y, width-1, height-1, r, r); Container parent = c.getParent(); if (parent!=null) {
@Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; Color cb = null; if (isMouseOver()) { cb = mouseOverColor; } else { cb = colorFront; } g2d.setColor(cb); RoundRectangle2D roundedRectangle = new RoundRectangle2D.Float(0, 0, getActualWidth() - 1, getActualHeight() - 1, PADDING_X, PADDING_Y); g2d.fill(roundedRectangle); g2d.setColor(cb); g2d.draw(roundedRectangle); roundedRectangle = new RoundRectangle2D.Float(1, 1, getActualWidth() - 3, getActualHeight() - 3, PADDING_X, PADDING_Y); g2d.setColor(colorFrame); g2d.draw(roundedRectangle); label.paintComponents(g); } }
@Override public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { draw(new RoundRectangle2D.Float(x, y, width, height, arcWidth, arcHeight)); }
@Override public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { fill(new RoundRectangle2D.Float(x, y, width, height, arcWidth, arcHeight)); }
@Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); RoundRectangle2D roundedRectangle = new RoundRectangle2D.Float(0, 0, getWidth(), getHeight(), 15, 15); g2d.fill(roundedRectangle); } }
public void drawRoundRect(int i, int j, int k, int l, int i1, int j1) { draw(new java.awt.geom.RoundRectangle2D.Float(i, j, k, l, i1, j1)); }
public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { fill(new java.awt.geom.RoundRectangle2D.Float(x, y, width, height, arcWidth, arcHeight)); }
@Implementation(minSdk = LOLLIPOP) protected void addRoundRect( float left, float top, float right, float bottom, float rx, float ry, Path.Direction dir) { mPath.append( new RoundRectangle2D.Float(left, top, right - left, bottom - top, rx * 2, ry * 2), false); }