List of usage examples for java.awt Graphics2D fillRect
public abstract void fillRect(int x, int y, int width, int height);
From source file:org.springframework.cloud.stream.app.image.recognition.processor.ImageRecognitionOutputMessageBuilder.java
/** * Augment the input image by adding the recognized classes. * * @param imageBytes input image as byte array * @param result computed recognition labels * @return the image augmented with recognized labels. *//* www. java 2s.com*/ private byte[] drawLabels(byte[] imageBytes, Object result) { try { if (result != null) { BufferedImage originalImage = ImageIO.read(new ByteArrayInputStream(imageBytes)); Graphics2D g = originalImage.createGraphics(); g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); FontMetrics fm = g.getFontMetrics(); Tuple resultTuple = new JsonStringToTupleConverter().convert(result.toString()); ArrayList<Tuple> labels = (ArrayList) resultTuple.getValues().get(0); int x = 1; int y = 1; for (Tuple l : labels) { String labelName = l.getFieldNames().get(0); int probability = (int) (100 * l.getFloat(0)); String title = labelName + ": " + probability + "%"; Rectangle2D rect = fm.getStringBounds(title, g); g.setColor(bgColor); g.fillRect(x, y, (int) rect.getWidth() + 6, (int) rect.getHeight()); g.setColor(textColor); g.drawString(title, x + 3, (int) (y + rect.getHeight() - 3)); y = (int) (y + rect.getHeight() + 1); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(originalImage, IMAGE_FORMAT, baos); baos.flush(); imageBytes = baos.toByteArray(); baos.close(); } } catch (IOException e) { logger.error("Failed to draw labels in the input image", e); } return imageBytes; }
From source file:uk.co.real_logic.aeron.tools.perf_tools.AeronLatencyUnderLoadPublisher.java
private void generateScatterPlot() throws IOException { final BufferedImage image = new BufferedImage(1800, 1000, BufferedImage.TYPE_INT_ARGB); final Graphics2D g2 = image.createGraphics(); final FontMetrics fm = g2.getFontMetrics(); final String filename = "throughputency.png"; final File imageFile = new File(filename); final int height = 940; double min = Double.MAX_VALUE; double max = Double.MIN_VALUE; for (final long timestamp : timestamps) { final double ts = timestamp / 1000.0; if (ts < min) { min = ts;/*ww w . j a v a 2 s . c o m*/ } if (ts > max) { max = ts; } } final double stepY = height / max; g2.setColor(Color.white); g2.fillRect(0, 0, 1800, 1000); g2.setColor(Color.black); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.drawString("Latency ScatterPlot (microseconds)", 900 - fm.stringWidth("Latency ScatterPlot (microseconds)") / 2, 20); g2.drawString("" + max, 10, 20); g2.drawLine(100, 20, 100, 960); g2.drawLine(100, 960, 1790, 960); int start = 0; int end = 100; final double width = 1690.0 / 7.0; g2.setColor(Color.red); plotSubset(g2, start, end, "10 msgs/sec", 100, width, stepY, means[0]); start = 100; end = 1100; g2.setColor(Color.green); plotSubset(g2, start, end, "100 msgs/sec", 100 + width, width, stepY, means[1]); start = 1100; end = 11100; g2.setColor(Color.blue); plotSubset(g2, start, end, "1K msgs/sec", 100 + width * 2, width, stepY, means[2]); start = 11100; end = 111100; g2.setColor(Color.cyan); plotSubset(g2, start, end, "10K msgs/sec", 100 + width * 3, width, stepY, means[3]); start = 111100; end = 1111100; g2.setColor(Color.magenta); plotSubset(g2, start, end, "100K msgs/sec", 100 + width * 4, width, stepY, means[4]); start = 1111100; end = 11111100; g2.setColor(Color.yellow); plotSubset(g2, start, end, "1M msgs/sec", 100 + width * 5, width, stepY, means[5]); start = 11111100; end = 41111100; g2.setColor(Color.orange); plotSubset(g2, start, end, "3M msgs/sec", 100 + width * 6, width, stepY, means[6]); ImageIO.write(image, "png", imageFile); }
From source file:ArrowIcon.java
protected void paintArrow(Graphics2D g, Color base, int x, int y) { g.setColor(base);//from ww w .java 2s .c om /* Path2D.Float arrowShape = new Path2D.Float(); arrowShape.moveTo(x, y-1); System.out.println("moveTo "+(x)+","+(y-1)); arrowShape.lineTo(size-1, y-1); System.out.println("lineTo "+(size-1)+","+(y-1)); arrowShape.lineTo(size/2, y+(size/2)); System.out.println("lineTo "+(size/2)+","+(y+(size/2))); arrowShape.lineTo(size/2 - 1, y+(size/2)); System.out.println("lineTo "+ (size/2 - 1)+","+(y+(size/2))); arrowShape.lineTo(x, y-1); System.out.println("lineTo "+(x)+","+(y-1)); g.fill(arrowShape); */ int len = size - 2; int xx = x; int yy = y - 1; while (len >= 2) { xx++; yy++; g.fillRect(xx, yy, len, 1); len -= 2; } }
From source file:org.openmeetings.app.data.record.BatikMethods.java
public void paintRect(Graphics2D g2d, int x, int y, int width, int height, Color linecoler, int thickness, Color fillColor) throws Exception { //int x, int y, int width, int height //g2d.fill(new Rectangle(x,y,width,height)); g2d.setStroke(new BasicStroke(thickness)); if (linecoler != null) { g2d.setPaint(linecoler);//from ww w . j a v a 2 s . co m g2d.drawRect(x, y, width, height); } if (fillColor != null) { g2d.setPaint(fillColor); g2d.fillRect(x, y, width, height); } }
From source file:org.tros.logo.swing.LogoPanel.java
@Override public void clear() { Drawable command = new Drawable() { @Override/* ww w . j a v a 2s. c om*/ public void draw(Graphics2D g2, TurtleState turtleState) { try { g2.setColor(Color.white); g2.fillRect(0, 0, turtleState.width > 0 ? (int) turtleState.width : getWidth(), turtleState.height > 0 ? (int) turtleState.height : getHeight()); turtleState.penColor = Color.black; g2.setColor(turtleState.penColor); turtleState.font = new Font(null, 0, 12); g2.setFont(turtleState.font); } catch (Exception ex) { } } @Override public void addListener(DrawListener listener) { } @Override public void removeListener(DrawListener listener) { } @Override public Drawable cloneDrawable() { return this; } }; submitCommand(command); }
From source file:org.squidy.designer.shape.ZoomShape.java
/** * @param paintContext/*from www . ja va 2 s.co m*/ */ protected void paintShapeZoomedIn(PPaintContext paintContext) { Shape shapeZoomedIn = getZoomedInShape(); if (shapeZoomedIn != null) { Graphics2D g = paintContext.getGraphics(); Rectangle bounds = shapeZoomedIn.getBounds(); g.setPaint(getZoomedInFillPaint()); if (isRenderPrimitiveRect()) g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height); else g.fill(shapeZoomedIn); g.setStroke(STROKE_ZOOMED_IN); g.setPaint(getZoomedInDrawPaint()); if (isRenderPrimitiveRect()) g.drawRect(bounds.x, bounds.y, bounds.width, bounds.height); else g.draw(shapeZoomedIn); } }
From source file:org.squidy.designer.shape.ZoomShape.java
/** * @param paintContext/* w ww. j a va2 s .c o m*/ */ protected void paintShapeZoomedOut(PPaintContext paintContext) { Shape shapeZoomedOut = getZoomedOutShape(); if (shapeZoomedOut != null) { Graphics2D g = paintContext.getGraphics(); Rectangle bounds = shapeZoomedOut.getBounds(); g.setPaint(getZoomedOutFillPaint()); if (isRenderPrimitiveRect()) g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height); else g.fill(shapeZoomedOut); g.setStroke(STROKE_ZOOMED_OUT); g.setPaint(getZoomedOutDrawPaint()); if (isRenderPrimitiveRect()) g.drawRect(bounds.x, bounds.y, bounds.width, bounds.height); else g.draw(shapeZoomedOut); } }
From source file:org.deegree.services.wps.provider.jrxml.contentprovider.map.MapContentProvider.java
private Object prepareLegend(String legendKey, XMLAdapter jrxmlAdapter, List<OrderedDatasource<?>> datasources, String type, int resolution) throws ProcessletException { if ("net.sf.jasperreports.engine.JRRenderable".equals(type)) { return new LegendRenderable(datasources, resolution); } else {/*from w w w . ja v a2s . c o m*/ OMElement legendRE = jrxmlAdapter.getElement(jrxmlAdapter.getRootElement(), new XPath( ".//jasper:image[jasper:imageExpression/text()='$P{" + legendKey + "}']/jasper:reportElement", nsContext)); if (legendRE != null) { LOG.debug("Found legend with key '" + legendKey + "'."); int width = jrxmlAdapter.getRequiredNodeAsInteger(legendRE, new XPath("@width", nsContext)); int height = jrxmlAdapter.getRequiredNodeAsInteger(legendRE, new XPath("@height", nsContext)); width = adjustSpan(width, resolution); height = adjustSpan(height, resolution); BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = bi.createGraphics(); // TODO: bgcolor? Color bg = Color.decode("0xFFFFFF"); g.setColor(bg); g.fillRect(0, 0, width, height); g.setColor(Color.BLACK); int k = 0; for (int i = 0; i < datasources.size(); i++) { if (k > height) { LOG.warn("The necessary legend size is larger than the available legend space."); } List<Pair<String, BufferedImage>> legends = datasources.get(i).getLegends(width); for (Pair<String, BufferedImage> legend : legends) { BufferedImage img = legend.second; if (img != null) { if (img.getWidth(null) < 50) { // it is assumed that no label is assigned g.drawImage(img, 0, k, null); g.drawString(legend.first, img.getWidth(null) + 10, k + img.getHeight(null) / 2); } else { g.drawImage(img, 0, k, null); } k = k + img.getHeight(null) + 10; } else { g.drawString("- " + legend.first, 0, k + 10); k = k + 20; } } } g.dispose(); return convertImageToReportFormat(type, bi); } } return null; }
From source file:org.tros.logo.swing.LogoPanel.java
@Override public void canvascolor(final String color) { Drawable command = new Drawable() { @Override/* ww w . j a v a2s. c om*/ public void draw(Graphics2D g2, TurtleState turtleState) { Color canvasColor = getColorByName(color); g2.setColor(canvasColor); g2.fillRect(0, 0, turtleState.width > 0 ? (int) turtleState.width : getWidth(), turtleState.height > 0 ? (int) turtleState.height : getHeight()); g2.setColor(turtleState.penColor); } @Override public void addListener(DrawListener listener) { } @Override public void removeListener(DrawListener listener) { } @Override public Drawable cloneDrawable() { return this; } }; submitCommand(command); }
From source file:au.com.gaiaresources.bdrs.controller.theme.ThemeControllerTest.java
private byte[] createTestImage() throws IOException { BufferedImage img = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = (Graphics2D) img.getGraphics(); Random rand = new Random(); g2.setColor(new Color(rand.nextInt(255), rand.nextInt(255), rand.nextInt(255))); g2.fillRect(0, 0, img.getWidth(), img.getHeight()); ByteArrayOutputStream baos = new ByteArrayOutputStream(img.getWidth() * img.getHeight()); ImageIO.write(img, "png", baos); baos.flush();/* w ww . j a v a 2s . co m*/ byte[] rawBytes = baos.toByteArray(); baos.close(); return rawBytes; }