List of usage examples for java.awt Graphics2D drawImage
public abstract void drawImage(BufferedImage img, BufferedImageOp op, int x, int y);
From source file:lucee.runtime.img.Image.java
public void threeBBger() throws ExpressionException { BufferedImage img = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_3BYTE_BGR); Graphics2D graphics = img.createGraphics(); graphics.drawImage(image(), new AffineTransformOp(AffineTransform.getTranslateInstance(0.0, 0.0), 1), 0, 0); graphics.dispose();//from www .j av a2 s.co m image(img); }
From source file:lucee.runtime.img.Image.java
public void rgb() throws ExpressionException { BufferedImage img = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_BYTE_INDEXED); Graphics2D graphics = img.createGraphics(); graphics.drawImage(image(), new AffineTransformOp(AffineTransform.getTranslateInstance(0.0, 0.0), 1), 0, 0); graphics.dispose();//from w w w.jav a 2 s . c o m image(img); }
From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java
/** * Paints the component by drawing the chart to fill the entire component, * but allowing for the insets (which will be non-zero if a border has been * set for this component). To increase performance (at the expense of * memory), an off-screen buffer image can be used. * * @param g the graphics device for drawing on. *///from w w w .j a v a 2s .co m public void paintComponent(final Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g.create(); Insets insets = getInsets(); if (bufferExtents == null || !bufferExtents.equals(getChartArea())) { createBuffer(); ((AbstractDmcPlot) chart.getPlot()).setNoData(true); Graphics2D bufferG2 = (Graphics2D) chartBuffer.getGraphics(); chart.draw(bufferG2, bufferExtents, info); } g2.drawImage(chartBuffer, insets.left, insets.right, this); this.verticalTraceLine = null; this.horizontalTraceLine = null; }
From source file:lucee.runtime.img.Image.java
public void paste(Image topImage, int x, int y) throws ExpressionException { RenderingHints interp = new RenderingHints(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); BorderExtender extender = BorderExtender.createInstance(1); Graphics2D g = getGraphics(); g.addRenderingHints(new RenderingHints(JAI.KEY_BORDER_EXTENDER, extender)); g.drawImage(topImage.image(), (new AffineTransformOp(AffineTransform.getTranslateInstance(x, y), interp)), 0, 0);/* ww w . j a v a 2 s. com*/ }
From source file:org.tsho.dmc2.core.chart.AbsorbingAreaRenderer.java
public void plotAttractor(Graphics2D g2, BufferedImage image, int imageX, int imageY) { //provisional disableAllActionsExceptStop();//from ww w . j a v a 2s .c om mouseClicked = false; while (!stopped) { while (!stopped && !mouseClicked) { delayExecution(); } if (stopped) { break; } mouseClicked = false; //mouse was clicked. Plot attractor starting from this point Point p = new Point(); p.set(xClicked - imageX, yClicked - imageY); int index = 0; for (int i = 0; i < iterations; i++) { if (i > transients) { if (getGridState(p) == 0) setGridState(p, attractorColor); } if (stopped) { stopped = false;//only plotting the attractor was stopped break; } iterate(p); index++; if (index == 1000) { index = 0; g2.drawImage(image, null, imageX, imageY); } } g2.drawImage(image, null, imageX, imageY); } copyDisplay(); stopped = false; enableAllActionsExceptStop(); mouseClicked = false; }
From source file:com.moviejukebox.plugin.DefaultImagePlugin.java
/** * Draw the language logo to the image/*from w w w . j a v a2s. co m*/ * * @param movie Movie file, used to determine the language * @param bi The image file to draw on * @return The new image file with the language flag on it */ private BufferedImage drawLanguage(IMovieBasicInformation movie, BufferedImage bi, int left, int top) { String lang = movie.getLanguage(); if (StringTools.isValidString(lang)) { String[] languages = lang.split("/"); StringBuilder fullLanguage = new StringBuilder(); for (String language : languages) { // CHeck the language is valid before adding it if (StringTools.isValidString(language)) { if (fullLanguage.length() > 0) { fullLanguage.append("_"); } fullLanguage.append(language.trim()); } } // If there isn't a valid language, quit if (StringTools.isNotValidString(fullLanguage.toString())) { return bi; } String languageFilename = "languages" + File.separator + fullLanguage + ".png"; try { Graphics2D g2d = bi.createGraphics(); File imageFile = new File(getResourcesPath() + languageFilename); if (imageFile.exists()) { BufferedImage biLang = GraphicTools.loadJPEGImage(imageFile); g2d.drawImage(biLang, 1, 1, null); } else if (languages.length == 1) { LOG.warn("Failed drawing Language logo to thumbnail file: {}", movie.getBaseName()); LOG.warn( "Please check that language specific graphic ({}.png) is in the resources/languages directory.", fullLanguage); } else { LOG.debug( "Unable to find multiple language image ({}.png) in the resources/languages directory, generating it from single one.", fullLanguage); int width = -1; int height = -1; int nbCols = (int) Math.sqrt(languages.length); int nbRows = languages.length / nbCols; BufferedImage[] imageFiles = new BufferedImage[languages.length]; // Looking for image file for (int i = 0; i < languages.length; i++) { String language = languages[i].trim(); languageFilename = "languages" + File.separator + language + ".png"; imageFile = new File(getResourcesPath() + languageFilename); if (imageFile.exists()) { BufferedImage biLang = GraphicTools.loadJPEGImage(imageFile); imageFiles[i] = biLang; // Determine image size. if (width == -1) { width = biLang.getWidth() / nbCols; height = biLang.getHeight() / nbRows; } } else { LOG.warn("Failed drawing Language logo to thumbnail file: {}", movie.getBaseName()); LOG.warn( "Please check that language specific graphic ({}) is in the resources/languages directory.", languageFilename); } } for (int i = 0; i < imageFiles.length; i++) { int indexCol = (i) % nbCols; int indexRow = (i / nbCols); g2d.drawImage(imageFiles[i], left + (width * indexCol), top + (height * indexRow), width, height, null); } } g2d.dispose(); } catch (FileNotFoundException ex) { LOG.warn(LOG_FAILED_TO_LOAD, languageFilename); } catch (IOException ex) { LOG.warn("Exception drawing Language logo to thumbnail file '{}': {}", movie.getBaseName(), ex.getMessage()); LOG.warn( "Please check that language specific graphic ({}) is in the resources/languages directory.", languageFilename); } } return bi; }
From source file:com.moviejukebox.plugin.DefaultImagePlugin.java
/** * Draw rounded corners on the image//from w w w .j a va 2s . c o m * * @param bi * @return */ protected BufferedImage drawRoundCorners(BufferedImage bi) { BufferedImage newImg = new BufferedImage(bi.getWidth(), bi.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D newGraphics = newImg.createGraphics(); newGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); RoundRectangle2D.Double rect = new RoundRectangle2D.Double(0, 0, bi.getWidth(), bi.getHeight(), rcqFactor * cornerRadius, rcqFactor * cornerRadius); newGraphics.setClip(rect); newGraphics.drawImage(bi, 0, 0, null); newGraphics.dispose(); return newImg; }
From source file:com.AandR.beans.plotting.imagePlotPanel.CanvasPanel.java
/** * *///from w w w. jav a 2 s . c o m @Override public void paintComponent(Graphics g) { super.paintComponent(g); setBackground(Color.GRAY); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (bufferedImage != null) { scaleGraphicsContext(g2); g2.drawImage(bufferedImage, 0, 0, null); drawTextBoxes(g2); } }
From source file:ucar.unidata.idv.control.chart.WayPoint.java
/** * Draws the annotation.//from w w w .j av a2 s .com * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param rendererIndex the renderer index. * @param info an optional info object that will be populated with * entity information. */ public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { super.setGraphicsState(g2); if (!getPlotWrapper().okToDraw(this)) { return; } g2.setStroke(new BasicStroke()); if (false && getSelected()) { g2.setColor(COLOR_SELECTED); } else { g2.setColor(getColor()); } x = getXFromValue(dataArea, domainAxis); int width2 = (int) (ANNOTATION_WIDTH / 2); int bottom = (int) (dataArea.getY() + dataArea.getHeight()); y = bottom; int[] xs = { x - width2, x + width2, x, x - width2 }; int[] ys = { bottom - ANNOTATION_WIDTH, bottom - ANNOTATION_WIDTH, bottom, bottom - ANNOTATION_WIDTH }; g2.fillPolygon(xs, ys, xs.length); if ((getName() != null) && !isForAnimation) { FontMetrics fm = g2.getFontMetrics(); int width = fm.stringWidth(getName()); int textLeft = x - width / 2; g2.drawString(getName(), textLeft, bottom - ANNOTATION_WIDTH - 2); } if (getSelected()) { g2.setColor(COLOR_SELECTED); g2.drawPolygon(xs, ys, xs.length); } if (getPropertyListeners().hasListeners(PROP_WAYPOINTVALUE) || isForAnimation) { g2.setColor(Color.gray); g2.drawLine(x, y - ANNOTATION_WIDTH, x, (int) dataArea.getY()); } boolean playSound = canPlaySound(); if (isForAnimation) { if (clockImage == null) { clockImage = GuiUtils.getImage("/auxdata/ui/icons/clock.gif"); } if (playSound) { g2.drawImage(clockImage, x - 8, (int) dataArea.getY() + 1, null); } else { g2.drawImage(clockImage, x - 8, (int) dataArea.getY() + 1, null); } } if (canPlaySound()) { if (noteImage == null) { noteImage = GuiUtils.getImage("/auxdata/ui/icons/note.gif"); } if (isForAnimation) { g2.drawImage(noteImage, x + 8, (int) dataArea.getY() + 1, null); } else { g2.drawImage(noteImage, x, (int) dataArea.getY() + 1, null); } } if (minutesSpan > 0.0) { int left = (int) domainAxis.valueToJava2D(domainValue - (minutesSpan * 60000) / 2, dataArea, RectangleEdge.BOTTOM); int right = (int) domainAxis.valueToJava2D(domainValue + (minutesSpan * 60000) / 2, dataArea, RectangleEdge.BOTTOM); g2.setPaint(Color.black); g2.setStroke(new BasicStroke(2.0f)); g2.drawLine(left, y, right, y); } }
From source file:lucee.runtime.img.Image.java
public void translate(int xtrans, int ytrans, Object interpolation) throws ExpressionException { RenderingHints hints = new RenderingHints(RenderingHints.KEY_INTERPOLATION, interpolation); if (interpolation != RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR) { hints.add(new RenderingHints(JAI.KEY_BORDER_EXTENDER, BorderExtender.createInstance(1))); }// ww w .ja va 2 s. c om ParameterBlock pb = new ParameterBlock(); pb.addSource(image()); BufferedImage img = JAI.create("translate", pb).getAsBufferedImage(); Graphics2D graphics = img.createGraphics(); graphics.clearRect(0, 0, img.getWidth(), img.getHeight()); AffineTransform at = new AffineTransform(); at.setToIdentity(); graphics.drawImage(image(), new AffineTransformOp(at, hints), xtrans, ytrans); graphics.dispose(); image(img); }