List of usage examples for java.awt Graphics2D setPaint
public abstract void setPaint(Paint paint);
From source file:com.pureinfo.srm.common.ImageHelper.java
public static void drawRectangle(Paint _color, Point _point, OutputStream _os) throws PureException { int nWidth = _point.x; int nHeight = _point.y; BufferedImage image = new BufferedImage(nWidth, nHeight, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.setPaint(_color); g2.fillRect(0, 0, nWidth, nHeight);/*ww w.jav a 2 s .c om*/ g2.dispose(); try { EncoderUtil.writeBufferedImage(image, ImageFormat.PNG, _os); } catch (Exception ex) { throw new PureException(PureException.UNKNOWN, "", ex); } }
From source file:Utils.java
public static BufferedImage createGradientImage(int width, int height, Color gradient1, Color gradient2) { BufferedImage gradientImage = createCompatibleImage(width, height); GradientPaint gradient = new GradientPaint(0, 0, gradient1, 0, height, gradient2, false); Graphics2D g2 = (Graphics2D) gradientImage.getGraphics(); g2.setPaint(gradient); g2.fillRect(0, 0, width, height);/* w ww . java2 s .co m*/ g2.dispose(); return gradientImage; }
From source file:org.jfree.graphics2d.demo.ImageTest.java
private static void drawGradientPaintTest(Graphics2D g2) { g2.setPaint(new GradientPaint(10f, 10f, Color.RED, 10f, 60f, Color.YELLOW)); g2.fillRect(10, 10, 50, 50);/*ww w . ja va 2s . c o m*/ g2.setPaint(Color.BLUE); g2.fillRect(60, 10, 50, 50); }
From source file:org.jfree.graphics2d.demo.ImageTest.java
private static void drawArcTest(Graphics2D g2) { g2.setPaint(Color.GREEN); g2.drawRect(0, 20, 70, 50);/*from w w w . j a v a 2 s .co m*/ 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
/** * Fills the given {@link BufferedImage} with a {@link Paint}, preserving its alpha channel. * * @param source The source image.// w w w .j a v a 2 s. co m * @param paint The paint to fill with. * @return A new, painted/filled image. */ public static BufferedImage filledImage(BufferedImage source, Paint paint) { BufferedImage newImage = newArgbBufferedImage(source.getWidth(), source.getHeight()); Graphics2D g = (Graphics2D) newImage.getGraphics(); g.drawImage(source, 0, 0, null); g.setComposite(AlphaComposite.SrcAtop); g.setPaint(paint); g.fillRect(0, 0, source.getWidth(), source.getHeight()); return newImage; }
From source file:Main.java
public static BufferedImage getStrokedImage(BufferedImage bi, Shape shape, int strokeWidth) { int w = bi.getWidth(); int h = bi.getHeight(); BufferedImage bib = new BufferedImage(w, h, bi.getType()); Graphics2D g = bib.createGraphics(); BasicStroke bs = new BasicStroke(strokeWidth); g.setStroke(bs);//from ww w. j a v a 2 s . co m Rectangle rect = new Rectangle(0, 0, w, h); TexturePaint tp = new TexturePaint(bi, rect); g.setPaint(tp); g.draw(shape); g.dispose(); return bib; }
From source file:Main.java
private static int[] makeGradientPallet() { BufferedImage image = new BufferedImage(100, 1, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); Point2D start = new Point2D.Float(0f, 0f); Point2D end = new Point2D.Float(99f, 0f); float[] dist = { 0.0f, 0.5f, 1.0f }; Color[] colors = { Color.RED, Color.YELLOW, Color.GREEN }; g2.setPaint(new LinearGradientPaint(start, end, dist, colors)); g2.fillRect(0, 0, 100, 1);/*from w w w . jav a2 s. c om*/ g2.dispose(); int width = image.getWidth(null); int[] pallet = new int[width]; PixelGrabber pg = new PixelGrabber(image, 0, 0, width, 1, pallet, 0, width); try { pg.grabPixels(); } catch (Exception e) { e.printStackTrace(); } return pallet; }
From source file:org.apache.fop.visual.BitmapComparator.java
/** * Builds a combined image that places a number of images next to each other for * manual, visual comparison./*from w w w . ja va 2s. c o m*/ * @param images the array of bitmaps * @return the combined image */ public static BufferedImage buildCompareImage(BufferedImage[] images) { BufferedImage cmp = new BufferedImage(images[0].getWidth() * images.length, images[0].getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g = cmp.createGraphics(); g.setPaint(Color.white); g.fillRect(0, 0, cmp.getWidth(), cmp.getHeight()); int lastWidth = 0; for (int i = 0; i < images.length; i++) { if (lastWidth > 0) { g.translate(lastWidth, 0); } if (images[i] != null) { g.drawImage(images[i], 0, 0, null); lastWidth = images[i].getWidth(); } else { lastWidth = 20; //Maybe add a special placeholder image instead later } } g.dispose(); return cmp; }
From source file:org.jfree.graphics2d.demo.ImageTest.java
private static void drawOldLinearGradientPaintTest(Graphics2D g2) { // top left/* w w w . j a va 2 s .c o m*/ GradientPaint lgp = new GradientPaint(10, 30, Color.RED, 50, 30, Color.BLUE); g2.setPaint(lgp); g2.fill(new Rectangle2D.Double(10, 10, 40, 40)); // top right lgp = new GradientPaint(80, 10, Color.RED, 80, 50, Color.BLUE); g2.setPaint(lgp); g2.fill(new Rectangle2D.Double(60, 10, 40, 40)); // bottom left lgp = new GradientPaint(10, 100, Color.RED, 50, 60, Color.BLUE); g2.setPaint(lgp); g2.fill(new Rectangle2D.Double(10, 60, 40, 40)); // bottom right lgp = new GradientPaint(70, 70, Color.RED, 90, 90, Color.BLUE); g2.setPaint(lgp); g2.fill(new Rectangle2D.Double(60, 60, 40, 40)); }
From source file:org.jfree.graphics2d.demo.ImageTest.java
private static void drawClipTest(Graphics2D g2) { g2.translate(10, 20);/*from w w w .jav a 2 s . c om*/ g2.setColor(Color.RED); g2.fillRect(10, 10, 100, 100); g2.clip(new Rectangle(0, 0, 60, 60)); g2.setPaint(Color.BLUE); g2.fillRect(10, 10, 100, 100); g2.setClip(null); g2.setPaint(Color.GREEN); g2.fillRect(60, 60, 50, 50); }