List of usage examples for java.awt Graphics2D drawRect
public void drawRect(int x, int y, int width, int height)
From source file:Main.java
/** * Creates an outline of an image,/*from www. j ava 2 s .co m*/ * with the default clipping rectangle. * @param src The source image. * @param c The color to outline the image * in. * @return */ public static BufferedImage imgUtilOutline(BufferedImage src, Color c) { if (src == null) return null; BufferedImage b = new BufferedImage(src.getWidth(), src.getHeight(), src.getType()); Graphics2D g = (Graphics2D) b.getGraphics(); g.setColor(c); g.drawRect(1, 1, src.getWidth() - 1, src.getHeight() - 1); g.drawImage(src, 0, 0, null); g.dispose(); return b; }
From source file:Main.java
public static BufferedImage drawBoundingBoxes(BufferedImage canvas, List<Rectangle> boxes, Color fgColour, Color bgColour) {// w ww. j av a 2 s .c o m Graphics2D g2d = canvas.createGraphics(); for (Rectangle r : boxes) { g2d.setColor(bgColour); g2d.drawRect(r.x - 1, r.y - 1, r.width + 2, r.height + 2); g2d.drawRect(r.x + 1, r.y + 1, r.width - 2, r.height - 2); g2d.setColor(fgColour); g2d.drawRect(r.x, r.y, r.width, r.height); } return canvas; }
From source file:Main.java
public static BufferedImage drawBoundingBoxes(BufferedImage canvas, Rectangle[] boxes, Color fgColour, Color bgColour) {//www.j a v a2 s .c o m Graphics2D g2d = canvas.createGraphics(); for (int i = 0; i < boxes.length; i++) { g2d.setColor(bgColour); g2d.drawRect(boxes[i].x - 1, boxes[i].y - 1, boxes[i].width + 2, boxes[i].height + 2); g2d.drawRect(boxes[i].x + 1, boxes[i].y + 1, boxes[i].width - 2, boxes[i].height - 2); g2d.setColor(fgColour); g2d.drawRect(boxes[i].x, boxes[i].y, boxes[i].width, boxes[i].height); } return canvas; }
From source file:org.jfree.graphics2d.demo.ImageTest.java
private static void drawArcTest(Graphics2D g2) { g2.setPaint(Color.GREEN);/*from w w w. j a va 2 s. c o m*/ g2.drawRect(0, 20, 70, 50); 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
public static BufferedImage highlightRegions(Image img, int[][] regions, int regionId, Color fgColour) { BufferedImage canvas = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = canvas.createGraphics(); g2d.drawImage(img, 0, 0, null);/*from w ww . ja v a 2s. c om*/ g2d.setColor(fgColour); for (int y = 0; y < regions.length; y++) { for (int x = 0; x < regions[y].length; x++) { if (regions[y][x] == regionId) { g2d.drawRect(x, y, 1, 1); } } } return canvas; }
From source file:de.codesourcery.planning.swing.DateAxis.java
protected static void debugBoundingBox(BoundingBox box, Graphics2D g) { if (DEBUG) {/* w w w. j a v a 2s . c o m*/ Color old = g.getColor(); g.setColor(Color.RED); g.drawRect(box.getX(), box.getY(), box.getWidth(), box.getHeight()); g.setColor(old); } }
From source file:juicebox.tools.utils.juicer.apa.APAPlotter.java
/** * Draw black border around main heat map * * @param g2 graphics2D object/*from w w w. j a va 2s .com*/ * @param heatMap object */ private static void drawHeatMapBorder(Graphics2D g2, HeatChart heatMap) { // calculate corners of heat map rectangle Point heatMapTL = heatMap.getHeatMapTL(); Point heatMapBR = heatMap.getHeatMapBR(); // plot border around heat map g2.setColor(Color.BLACK); g2.drawRect(heatMapTL.x, heatMapTL.y, heatMapBR.x - heatMapTL.x, heatMapBR.y - heatMapTL.y); }
From source file:edu.umn.cs.spatialHadoop.nasa.MultiHDFPlot.java
/** * Draws a scale used with the heat map// w w w . j a va 2s . c o m * @param output * @param valueRange * @param width * @param height * @throws IOException */ private static void drawVerticalScale(Path output, double min, double max, int width, int height, OperationsParams params) 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 HDFPlot.HDFRasterizer gradient = new HDFPlot.HDFRasterizer(); gradient.configure(params); HDFRasterLayer gradientLayer = (HDFRasterLayer) gradient.createCanvas(0, 0, new Rectangle()); for (int y = 0; y < height; y++) { Color color = gradientLayer.calculateColor(height - y, 0, height); g.setColor(color); g.drawRect(width * 3 / 4, y, width / 4, 1); } int fontSize = 24; g.setFont(new Font("Arial", Font.BOLD, fontSize)); double step = (max - min) * fontSize * 5 / height; step = (int) (Math.pow(10.0, Math.round(Math.log10(step)))); double min_value = Math.floor(min / step) * step; double max_value = Math.floor(max / step) * step; g.setColor(Color.WHITE); for (double value = min_value; value <= max_value; value += step) { double y = ((value - min) + (max - value) * (height - fontSize)) / (max - min); g.drawString(String.valueOf((int) value), 5, (int) 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.umn.cs.spatialHadoop.nasa.MultiHDFPlot.java
/** * Draws a scale used with the heat map/*w w w .j ava 2s.c o m*/ * @param output * @param valueRange * @param width * @param height * @throws IOException */ private static void drawHorizontalScale(Path output, double min, double max, int width, int height, OperationsParams params) 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); int fontSize = 24; // fix this part to work according to color1, color2 and gradient type HDFPlot.HDFRasterizer gradient = new HDFPlot.HDFRasterizer(); gradient.configure(params); HDFRasterLayer gradientLayer = (HDFRasterLayer) gradient.createCanvas(0, 0, new Rectangle()); for (int x = 0; x < width; x++) { Color color = gradientLayer.calculateColor(x, 0, width); g.setColor(color); g.drawRect(x, height - (fontSize - 5), 1, fontSize - 5); } g.setFont(new Font("Arial", Font.BOLD, fontSize)); double step = (max - min) * fontSize * 5 / width; step = (int) (Math.pow(10.0, Math.round(Math.log10(step)))); double min_value = Math.floor(min / step) * step; double max_value = Math.floor(max / step) * step; g.setColor(Color.WHITE); for (double value = min_value; value <= max_value; value += step) { double x = ((value - min) * (width - fontSize) + (max - value)) / (max - min); g.drawString(String.valueOf((int) value), (int) x, fontSize); } g.dispose(); FileSystem fs = output.getFileSystem(new Configuration()); FSDataOutputStream outStream = fs.create(output, true); ImageIO.write(image, "png", outStream); outStream.close(); }
From source file:Rectangles.java
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; g2d.setColor(new Color(212, 212, 212)); g2d.drawRect(10, 15, 90, 60); g2d.setColor(new Color(31, 21, 1)); g2d.fillRect(250, 195, 90, 60);/*ww w. jav a 2 s. com*/ }