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.n52.oxf.render.sos.AnimatedMapChartRenderer4OnePhenomenon.java
/** * /*from w w w . jav a2s . c o m*/ * @param observationCollection * the observations belonging to the timeStamp (frame) which shall be rendered * @param screenW * @param screenH * @param bbox * @return */ protected Image renderFrame(ITimePosition timePos, int screenW, int screenH, IBoundingBox bbox, Set<OXFFeature> featuresWithCharts, ObservationSeriesCollection tupleFinder) { ContextBoundingBox contextBBox = new ContextBoundingBox(bbox); BufferedImage image = new BufferedImage(screenW, screenH, BufferedImage.TYPE_INT_RGB); Graphics2D g = image.createGraphics(); // draw white background: g.setColor(Color.WHITE); g.fillRect(0, 0, screenW, screenH); for (OXFFeature chartFeature : featuresWithCharts) { // // create Plot for each "chart feature" and add it to the plotArray: // CategoryPlot plot = renderFoiBarChart(chartFeature.getID(), timePos.toString(), tupleFinder.getTuple(chartFeature, timePos)); // // draw the plots into the image at the georeferenced position of the corresponding chartFeature: // Point pRealWorld = (Point) chartFeature.getGeometry(); java.awt.Point pScreen = ContextBoundingBox.realworld2Screen(contextBBox.getActualBBox(), screenW, screenH, new Point2D.Double(pRealWorld.getCoordinate().x, pRealWorld.getCoordinate().y)); plot.getRangeAxis(0).setRange((Double) tupleFinder.getMinimum(0), (Double) tupleFinder.getMaximum(0)); plot.draw(g, new Rectangle2D.Float(pScreen.x + X_SHIFT + 10, pScreen.y + Y_SHIFT, CHART_WIDTH, CHART_HEIGHT), null, null, null); } return image; }
From source file:org.n52.io.img.ChartRenderer.java
private BufferedImage drawChartToImage() { int width = getChartStyleDefinitions().getWidth(); int height = getChartStyleDefinitions().getHeight(); BufferedImage chartImage = new BufferedImage(width, height, TYPE_INT_RGB); Graphics2D chartGraphics = chartImage.createGraphics(); chartGraphics.fillRect(0, 0, width, height); chartGraphics.setColor(WHITE);/* www .j a va2 s.com*/ chart.setTextAntiAlias(true); chart.setAntiAlias(true); chart.draw(chartGraphics, new Rectangle2D.Float(0, 0, width, height)); return chartImage; }
From source file:image.writer.ImageWriterExample1.java
/** * Paints a few things on a Graphics2D instance. * @param g2d the Graphics2D instance//from w w w . jav a2s . c om * @param pageNum a page number */ protected void paintSome(Graphics2D g2d, int pageNum) { //Paint a bounding box g2d.drawRect(0, 0, 400, 200); //A few rectangles rotated and with different color Graphics2D copy = (Graphics2D) g2d.create(); int c = 12; for (int i = 0; i < c; i++) { float f = ((i + 1) / (float) c); Color col = new Color(0.0f, 1 - f, 0.0f); copy.setColor(col); copy.fillRect(70, 90, 50, 50); copy.rotate(-2 * Math.PI / (double) c, 70, 90); } copy.dispose(); //Some text copy = (Graphics2D) g2d.create(); copy.rotate(-0.25); copy.setColor(Color.RED); copy.setFont(new Font("sans-serif", Font.PLAIN, 36)); copy.drawString("Hello world!", 140, 140); copy.setColor(Color.RED.darker()); copy.setFont(new Font("serif", Font.PLAIN, 36)); copy.drawString("Hello world!", 140, 180); copy.dispose(); //Try attributed text AttributedString aString = new AttributedString("This is attributed text."); aString.addAttribute(TextAttribute.FAMILY, "SansSerif"); aString.addAttribute(TextAttribute.FAMILY, "Serif", 8, 18); aString.addAttribute(TextAttribute.FOREGROUND, Color.orange, 8, 18); g2d.drawString(aString.getIterator(), 250, 170); g2d.drawString("Page: " + pageNum, 250, 190); }
From source file:org.apache.fop.pdf.PDFDocumentGraphics2DTestCase.java
/** * Does a smoke test on PDFDocumentGraphics2D making sure that nobody accidentally broke * anything serious. It does not check the correctness of the produced PDF. * @throws Exception if an error occurs/*from www . j a va 2 s . c om*/ */ @Test public void smokeTest() throws Exception { ByteArrayOutputStream baout = new ByteArrayOutputStream(); PDFDocumentGraphics2D g2d = new PDFDocumentGraphics2D(false); g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext()); //Set up the document size Dimension pageSize = new Dimension((int) Math.ceil(UnitConv.mm2pt(210)), (int) Math.ceil(UnitConv.mm2pt(297))); //page size A4 (in pt) g2d.setupDocument(baout, pageSize.width, pageSize.height); //A few rectangles rotated and with different color Graphics2D copy = (Graphics2D) g2d.create(); int c = 12; for (int i = 0; i < c; i++) { float f = ((i + 1) / (float) c); Color col = new Color(0.0f, 1 - f, 0.0f); copy.setColor(col); copy.fillRect(70, 90, 50, 50); copy.rotate(-2 * Math.PI / c, 70, 90); } copy.dispose(); //Some text g2d.rotate(-0.25); g2d.setColor(Color.RED); g2d.setFont(new Font("sans-serif", Font.PLAIN, 36)); g2d.drawString("Hello world!", 140, 140); g2d.setColor(Color.RED.darker()); g2d.setFont(new Font("serif", Font.PLAIN, 36)); g2d.drawString("Hello world!", 140, 180); g2d.nextPage(); //Move to next page g2d.setFont(new Font("sans-serif", Font.PLAIN, 36)); g2d.drawString("Welcome to page 2!", 140, 140); //Cleanup g2d.finish(); String pdfString = baout.toString("ISO-8859-1"); Assert.assertEquals("%%EOF not found", pdfString.substring(pdfString.length() - 6), "%%EOF\n"); }
From source file:net.sf.maltcms.chromaui.project.spi.nodes.DescriptorNode.java
@Override public Image getIcon(int type) { Image descrImage = DescriptorFactory.getImage(getBean()); int w = descrImage.getWidth(null); int h = descrImage.getHeight(null); if (getBean() instanceof IColorizableDescriptor) { IColorizableDescriptor colorDescr = (IColorizableDescriptor) getBean(); Color c = colorDescr.getColor(); if (c != null) { BufferedImage bi = new BufferedImage(w / 10, h / 10, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = bi.createGraphics(); g2.setColor(colorDescr.getColor()); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.9f)); g2.fillRect(0, 0, bi.getWidth(), bi.getHeight()); descrImage = ImageUtilities.mergeImages(bi, descrImage, w - bi.getWidth(), h - bi.getHeight()); }/*from ww w . j a va 2 s .c om*/ } return descrImage; }
From source file:edu.csudh.goTorosBank.WithdrawServlet.java
public String writeIntoCheck(String filePath, String username, String theAmount, String amountInWords, String dateWrote, String person_payingto, String billType) throws IOException, NullPointerException { File blueCheck = new File("blank-blue-check.jpg"); String pathToOriginal = getServletContext().getRealPath("/" + blueCheck); File file = new File(pathToOriginal); BufferedImage imageToCopy = null; try {//w w w . j av a2s. c o m imageToCopy = ImageIO.read(file); } catch (IOException e) { e.printStackTrace(); } String amount = theAmount; String person_gettingPayed = person_payingto; String amountinWords = amountInWords; String date = dateWrote; String bill_type = billType; int w = imageToCopy.getWidth(); int h = imageToCopy.getHeight(); BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = img.createGraphics(); g2d.setColor(g2d.getBackground()); g2d.fillRect(0, 0, w, h); g2d.drawImage(imageToCopy, 0, -100, null); g2d.setPaint(Color.black); g2d.setFont(new java.awt.Font("Serif", Font.BOLD, 36)); //g2d.setFont(new Font("Serif", Font.BOLD, 36)); FontMetrics fm = g2d.getFontMetrics(); int x = img.getWidth() - fm.stringWidth(amount) - 100; int y = fm.getHeight(); g2d.drawString(amount, x - 70, y + 335); g2d.drawString(person_gettingPayed, x - 800, y + 329); g2d.drawString(amountinWords, x - 940, y + 390); g2d.drawString(date, x - 340, y + 245); g2d.drawString(bill_type, x - 900, y + 530); String signature = "Use The Force"; g2d.setFont(new java.awt.Font("Monotype Corsiva", Font.BOLD | Font.ITALIC, 36)); g2d.drawString(signature, x - 340, y + 530); g2d.dispose(); /*write check to file*/ String filename = fileNameGenerator(username); String fullname = filePath + "_" + filename + ".jpg"; ImageIO.write(img, "jpg", new File(fullname)); return fullname; }
From source file:org.evors.rs.ui.sandpit.TrialViewer.java
@Override public void draw() { if (buffer == null) { return;//from w ww .j av a 2s . com } Graphics2D g2 = (Graphics2D) buffer.getDrawGraphics(); camera.setWindowSize(new Vector2D(this.getWidth(), this.getHeight())); g2.setColor(Color.WHITE); g2.fillRect(0, 0, getWidth(), getHeight()); AffineTransform prevTrans = g2.getTransform(); g2.setTransform(camera.getTransform()); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); grid.draw(g2); if (world != null) { SandpitRenderer.drawWorld(g2, world); } if (path != null) { path.draw(g2); } if (robot != null) { SandpitRenderer.drawRobot(g2, robot); } g2.setTransform(prevTrans); drawText(g2, String.format("Time: %.2f\nRobot position: {%.2f,%.2f}\nRobot heading: %.2f\nInputs:%s\nNeurons:%s", time, robot.getPosition().getX(), robot.getPosition().getY(), robot.getHeading(), Arrays.toString(robot.getInput()), Arrays.toString(((CTRNN) controller.getController()).getNeurons()))); }
From source file:ImageBorderHack.java
public void fillTexture(Graphics2D g2, Image img, int x, int y, int w, int h) { BufferedImage buff = createBufferedImage(img); Rectangle anchor = new Rectangle(x, y, img.getWidth(null), img.getHeight(null)); TexturePaint paint = new TexturePaint(buff, anchor); g2.setPaint(paint);/*w w w.jav a 2s. co m*/ g2.fillRect(x, y, w, h); }
From source file:org.n52.io.measurement.img.ChartIoHandler.java
private BufferedImage createImage() { int width = getChartStyleDefinitions().getWidth(); int height = getChartStyleDefinitions().getHeight(); BufferedImage chartImage = new BufferedImage(width, height, TYPE_INT_RGB); Graphics2D chartGraphics = chartImage.createGraphics(); chartGraphics.fillRect(0, 0, width, height); chartGraphics.setColor(WHITE);//from w w w .j av a2s . c o m chart.setTextAntiAlias(true); chart.setAntiAlias(true); if (chart.getLegend() != null) { chart.getLegend().setFrame(BlockBorder.NONE); } chart.draw(chartGraphics, new Rectangle2D.Float(0, 0, width, height)); return chartImage; }
From source file:piramide.interaction.reasoner.FuzzyReasonerWizardFacade.java
private BufferedImage createErrorMessagesImage(String text) { final Font font = TextTitle.DEFAULT_FONT; final Font bigBold = new Font(font.getName(), Font.BOLD, 24); final FontRenderContext frc = new FontRenderContext(null, true, false); final TextLayout layout = new TextLayout(text, bigBold, frc); final Rectangle2D bounds = layout.getBounds(); final int w = (int) Math.ceil(bounds.getWidth()); final int h = (int) Math.ceil(bounds.getHeight()); final BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); final Graphics2D g = image.createGraphics(); g.setColor(Color.WHITE);/*w ww.ja v a 2s . com*/ g.fillRect(0, 0, w, h); g.setColor(Color.RED); g.setFont(bigBold); g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF); g.drawString(text, (float) -bounds.getX(), (float) -bounds.getY()); g.dispose(); return image; }