List of usage examples for java.awt Graphics2D setColor
public abstract void setColor(Color c);
From source file:org.jax.maanova.plot.MaanovaChartPanel.java
/** * Render the selection rectangle/* w w w .j av a 2 s . c o m*/ * @param graphics2D * the graphics context to render to */ protected synchronized void renderDragRectangle(Graphics2D graphics2D) { Rectangle2D nonNegativeSelectionRectangle = MaanovaChartPanel .toNonNegativeWidthHeightRectangle(this.dragRectangle); graphics2D.setColor(this.getSelectionRectangleFillColor()); graphics2D.fill(nonNegativeSelectionRectangle); graphics2D.setColor(this.getSelectionRectangleColor()); graphics2D.draw(nonNegativeSelectionRectangle); }
From source file:net.sf.maltcms.chromaui.chromatogram2Dviewer.datastructures.annotations.AnnotationLayer.java
/** * * @param gd//www . ja v a2s . c om * @param xyplot * @param rd * @param va * @param va1 * @param i * @param pri */ @Override public void draw(Graphics2D gd, XYPlot xyplot, Rectangle2D rd, ValueAxis va, ValueAxis va1, int i, PlotRenderingInfo pri) { if (visible) { Color oldC = gd.getColor(); for (XYSelectableShapeAnnotation<?> xys : this.xya) { xys.draw(gd, xyplot, rd, va, va1, i, pri); } gd.setColor(oldC); } }
From source file:com.celements.photo.image.GenerateThumbnail.java
private void drawString(String copyright, int width, int height, int bottomSpace, int rightSpace, int vSpacing, int hSpacing, FontMetrics metrics, Graphics2D g2d) { AlphaComposite transprency;/*from www . j a va2s. c o m*/ g2d.setColor(new Color(255, 255, 255)); transprency = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.66f); g2d.setComposite(transprency); //Attention: drawString's [x, y] coordinates are the baseline, not upper or lower corner. g2d.drawString(copyright, width - metrics.stringWidth(copyright) - hSpacing - rightSpace, height - metrics.getDescent() - vSpacing - bottomSpace); }
From source file:edu.umn.cs.spatialHadoop.operations.GeometricPlot.java
/** * Draws an image that can be used as a scale for heat maps generated using * Plot or PlotPyramid./*from ww w .j a v a 2 s.co m*/ * @param output - Output path * @param valueRange - Range of values of interest * @param width - Width of the generated image * @param height - Height of the generated image * @throws IOException */ public static void drawScale(Path output, MinMax valueRange, int width, int height) throws IOException { BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); g.setBackground(Color.BLACK); g.clearRect(0, 0, width, height); // fix this part to work according to color1, color2 and gradient type for (int y = 0; y < height; y++) { Color color = NASARectangle.calculateColor(y); g.setColor(color); g.drawRect(width * 3 / 4, y, width / 4, 1); } int fontSize = 24; g.setFont(new Font("Arial", Font.BOLD, fontSize)); int step = (valueRange.maxValue - valueRange.minValue) * fontSize * 10 / height; step = (int) Math.pow(10, Math.round(Math.log10(step))); int min_value = valueRange.minValue / step * step; int max_value = valueRange.maxValue / step * step; for (int value = min_value; value <= max_value; value += step) { int y = fontSize + (height - fontSize) - value * (height - fontSize) / (valueRange.maxValue - valueRange.minValue); g.setColor(Color.WHITE); g.drawString(String.valueOf(value), 5, y); } g.dispose(); FileSystem fs = output.getFileSystem(new Configuration()); FSDataOutputStream outStream = fs.create(output, true); ImageIO.write(image, "png", outStream); outStream.close(); }
From source file:edu.kit.dama.ui.components.TextImage.java
/** * Get the bytes of the final image./*from ww w.ja va 2 s . com*/ * * @return The byte array containing the bytes of the resulting image. * * @throws IOException if creating the image fails. */ public byte[] getBytes() throws IOException { Image transparentImage = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource( new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB).getSource(), new RGBImageFilter() { @Override public final int filterRGB(int x, int y, int rgb) { return (rgb << 8) & 0xFF000000; } })); //create the actual image and overlay it by the transparent background BufferedImage outputImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = outputImage.createGraphics(); g2d.drawImage(transparentImage, 0, 0, null); //draw the remaining stuff g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2d.setColor(color); g2d.fillRoundRect(0, 0, size, size, 20, 20); g2d.setColor(new Color(Math.round((float) color.getRed() * .9f), Math.round((float) color.getGreen() * .9f), Math.round((float) color.getBlue() * .9f))); g2d.drawRoundRect(0, 0, size - 1, size - 1, 20, 20); Font font = new Font("Dialog", Font.BOLD, size - 4); g2d.setFont(font); g2d.setColor(Color.WHITE); String s = text.toUpperCase().substring(0, 1); FontMetrics fm = g2d.getFontMetrics(); float x = ((float) size - (float) fm.stringWidth(s)) / 2f; float y = ((float) fm.getAscent() + (float) ((float) size - ((float) fm.getAscent() + (float) fm.getDescent())) / 2f) - 1f; g2d.drawString(s, x, y); ByteArrayOutputStream bout = new ByteArrayOutputStream(); ImageIO.write(outputImage, "png", bout); g2d.dispose(); return bout.toByteArray(); }
From source file:org.osjava.reportrunner_plugins.renderers.jfreechart.creators.TexturedBarRenderer.java
public java.awt.Paint getSeriesPaint(int row) { BufferedImage bufferedImage = new BufferedImage(5, 5, BufferedImage.TYPE_INT_RGB); Graphics2D big = bufferedImage.createGraphics(); TexturePaint texture = null;/*from w ww . ja va2 s . co m*/ int rowNum = row + 1; int patNum = 13; int formula = rowNum - ((rowNum / patNum) * patNum); if (formula == 0) { big.setColor(Color.orange); big.fillRect(0, 0, 5, 5); big.fillRect(1, 0, 5, 5); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 1) { big.setColor(Color.red); big.fillRect(0, 0, 5, 5); big.fillRect(1, 0, 5, 5); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 2) { Color color = Color.blue; big.setColor(Color.white); big.fillRect(0, 0, 5, 5); big.setColor(color); big.fillRect(0, 1, 5, 5); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 3) { Color color = Color.yellow; big.setColor(Color.orange); big.fillRect(0, 0, 5, 5); big.setColor(color); big.fillRect(1, 1, 4, 4); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 4) { big.setColor(Color.green); big.fillRect(0, 0, 5, 5); big.fillRect(1, 0, 5, 5); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 5) { big.setColor(Color.magenta); big.fillRect(0, 0, 5, 5); big.setColor(Color.pink); big.fillRect(0, 0, 4, 4); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 6) { float[] x = { .5f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.5f, 5.0f }; float[] y = { .5f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.5f, 5.0f }; GeneralPath path = new GeneralPath(); path.moveTo(x[0], y[0]); for (int j = 1; j < x.length; j++) { path.lineTo(x[j], y[j]); } big.setColor(new Color(226, 199, 252)); big.fillRect(0, 0, 5, 5); big.setColor(Color.blue); big.setStroke(new BasicStroke(1.0f)); big.draw(path); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 7) { big.setColor(Color.lightGray); big.fillRect(0, 0, 5, 5); big.setColor(Color.red); big.fillRect(1, 0, 5, 5); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 8) { float[] x = { .5f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.5f, 5.0f }; float[] y = { .5f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.5f, 5.0f }; GeneralPath path = new GeneralPath(); path.moveTo(x[0], y[0]); for (int j = 1; j < x.length; j++) { path.lineTo(x[j], y[j]); } big.setColor(Color.blue); big.fillRect(0, 0, 5, 5); big.setColor(Color.cyan); big.setStroke(new BasicStroke(2.0f)); big.draw(path); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 9) { Color color = new Color(0xBBBBDD); big.setColor(color); big.fillRect(0, 0, 5, 5); big.setColor(new Color(199, 201, 230)); big.fillRect(1, 0, 5, 5); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 10) { float[] x = { 1, 2, 3, 4, 5 }; float[] y = { 1, 2, 3, 4, 5 }; GeneralPath path = new GeneralPath(); path.moveTo(x[0], y[1]); path.lineTo(x[1], y[0]); path.moveTo(x[0], y[2]); path.lineTo(x[2], y[0]); path.moveTo(x[0], y[3]); path.lineTo(x[3], y[0]); path.moveTo(x[0], y[4]); path.lineTo(x[4], y[0]); big.setColor(Color.red); big.fillRect(0, 0, 5, 5); big.setColor(new Color(242, 242, 193)); big.setStroke(new BasicStroke(3.0f)); big.draw(path); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 11) { big.setColor(new Color(252, 169, 171)); big.fillOval(0, 0, 5, 6); big.setColor(new Color(252, 230, 230)); big.fillOval(0, 0, 3, 3); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 12) { big.setColor(Color.green); big.fillRect(0, 0, 5, 5); big.setColor(new Color(20, 178, 38)); big.fillRect(2, 2, 5, 5); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } return texture; }
From source file:org.amanzi.awe.render.network.NetworkRenderer.java
/** * render sector element on map//ww w. j a v a2s.co m * * @param destination * @param point * @param element */ private void renderSector(final Graphics2D destination, final Point point, final double azimuth, final double beamwidth, final IDataElement sector) { int size = getSize(); int x = getSectorXCoordinate(point, size); int y = getSectorYCoordinate(point, size); destination.setColor(networkRendererStyle.changeColor(getColor(sector), networkRendererStyle.getAlpha())); GeneralPath path = new GeneralPath(); path.moveTo(x, y); Arc2D a = createSector(point, networkRendererStyle.getLargeElementSize(), getAngle(azimuth, beamwidth), beamwidth); path.append(a.getPathIterator(null), true); path.closePath(); destination.draw(path); destination.fill(path); // create border destination.setColor(networkRendererStyle.getBorderColor()); destination.draw(path); }
From source file:Composite.java
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; Dimension d = getSize();/*from ww w . j ava 2 s.c om*/ int w = d.width; int h = d.height; // Creates the buffered image. BufferedImage buffImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D gbi = buffImg.createGraphics(); // Clears the previously drawn image. g2.setColor(Color.white); g2.fillRect(0, 0, d.width, d.height); int rectx = w / 4; int recty = h / 4; // Draws the rectangle and ellipse into the buffered image. gbi.setColor(new Color(0.0f, 0.0f, 1.0f, 1.0f)); gbi.fill(new Rectangle2D.Double(rectx, recty, 150, 100)); gbi.setColor(new Color(1.0f, 0.0f, 0.0f, 1.0f)); gbi.setComposite(ac); gbi.fill(new Ellipse2D.Double(rectx + rectx / 2, recty + recty / 2, 150, 100)); // Draws the buffered image. g2.drawImage(buffImg, null, 0, 0); }
From source file:business.model.CaptchaModel.java
/** * * @param CaptchaText//from ww w. jav a2 s . com * @return */ public static BufferedImage CreateCaptchaImageOld(String CaptchaText) { BufferedImage localBufferedImage = new BufferedImage(width, height, 1); try { Graphics2D localGraphics2D = localBufferedImage.createGraphics(); // List<Font> fonts = FontFactory.getListFont(); List<Font> fonts = new ArrayList<Font>(); if (fonts.isEmpty()) { fonts.add(new Font("Nimbus Roman No9 L", 1, 30)); fonts.add(new Font("VN-NTime", 1, 30)); fonts.add(new Font("DT-Times", 1, 30)); fonts.add(new Font("Times New Roman", 1, 30)); fonts.add(new Font("Vni-Book123", 1, 30)); fonts.add(new Font("VNI-Centur", 1, 30)); fonts.add(new Font("DT-Brookly", 1, 30)); } // fonts.add(loadFont("BINHLBI.TTF")); RenderingHints localRenderingHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); localRenderingHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); localGraphics2D.setRenderingHints(localRenderingHints); localGraphics2D.fillRect(0, 0, width, height); localGraphics2D.setColor(new Color(50, 50, 50)); Random localRandom = new Random(); int i = 0; int j = 0; for (int k = 0; k < CaptchaText.length(); k++) { i += 25 + Math.abs(localRandom.nextInt()) % 5; j = 25 + Math.abs(localRandom.nextInt()) % 20; int tmp = localRandom.nextInt(fonts.size() - 1); localGraphics2D.setFont(fonts.get(tmp)); localGraphics2D.drawChars(CaptchaText.toCharArray(), k, 1, i, j); } localBufferedImage = getDistortedImage(localBufferedImage); Graphics2D localGraphics2D2 = localBufferedImage.createGraphics(); localGraphics2D2.setRenderingHints(localRenderingHints); // localGraphics2D2.fillRect(0, 0, width, height); localGraphics2D2.setColor(new Color(50, 50, 50)); CubicCurve2D c = new CubicCurve2D.Double();// draw QuadCurve2D.Float with set coordinates for (int l = 0; l < 7; l++) { int x1 = Util.rand(0, width / 2); ; int x2 = Util.rand(width / 2, width); int y1 = Util.rand(0, height); int y2 = Util.rand(0, height); int ctrlx1 = (x1 + x2) / 4 * Util.rand(1, 3); int ctrly1 = y1; int ctrlx2 = (x1 + x2) / 4 * Util.rand(1, 3); int ctrly2 = y2; c.setCurve(x1, y1, ctrlx2, ctrly2, ctrlx1, ctrly1, x2, y2); localGraphics2D2.draw(c); // localGraphics2D2.drawLine(randomX1(), randomY1(), randomX2(), randomY2()); } localGraphics2D.dispose(); } catch (Exception e) { log.error(e.getMessage(), e); return null; } return localBufferedImage; }
From source file:com.celements.photo.image.GenerateThumbnail.java
BufferedImage convertImageToBufferedImage(Image thumbImg, String watermark, String copyright, Color defaultBg) { BufferedImage thumb = new BufferedImage(thumbImg.getWidth(null), thumbImg.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = thumb.createGraphics(); if (defaultBg != null) { g2d.setColor(defaultBg); g2d.fillRect(0, 0, thumbImg.getWidth(null), thumbImg.getHeight(null)); }/*from w ww . jav a2 s . c om*/ g2d.drawImage(thumbImg, 0, 0, null); if ((watermark != null) && (!watermark.equals(""))) { drawWatermark(watermark, g2d, thumb.getWidth(), thumb.getHeight()); } if ((copyright != null) && (!copyright.equals(""))) { drawCopyright(copyright, g2d, thumb.getWidth(), thumb.getHeight()); } mLogger.info("thumbDimensions: " + thumb.getHeight() + "x" + thumb.getWidth()); return thumb; }