List of usage examples for java.awt.image BufferedImage BufferedImage
public BufferedImage(int width, int height, int imageType)
From source file:com.liud.dailynote.ThumbnailatorTest.java
public void testYS7() throws IOException { String result = "src/main/resources/images/"; BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); Graphics2D g = bi.createGraphics(); g.setColor(Color.LIGHT_GRAY); g.drawRect(0, 0, 10, 10);// www. jav a 2 s.c om char[] data = "liudTest".toCharArray(); g.drawChars(data, 0, data.length, 5, 32); // watermark ? 1.? 2.? 3.? Thumbnails.of(result + "sijili.jpg").scale(1.0f).watermark(Positions.CENTER, bi, 1.0f) .toFile(result + "image_warter_liud.jpg"); }
From source file:bachelorthesis.captchabuilder.builder.CaptchaBuilder.java
/** * Constructor//from w w w. j a v a 2 s . c o m * * @param width the width of the captcha to be created * @param height the width of the captcha to be created * @param buildSequence string arguments to create the captcha * <p/> * @throws ParseException */ public CaptchaBuilder(int width, int height, String buildSequence) throws ParseException { this.builders = new ArrayDeque<>(); this.setBuildSequence(buildSequence); img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); answer = ""; }
From source file:org.iish.visualmets.services.ImageTransformation.java
/** * Returns a scaled BufferedImage//from w ww .j a va2 s . co m * * @param bi current image * @param maxWidth new width * @param maxHeight new height * @return a new/scaled image */ /*public static BufferedImage ScaleImage(BufferedImage image, int width, int height) throws IOException { int imageWidth = image.getWidth(); int imageHeight = image.getHeight(); double scaleX = (double)width/imageWidth; double scaleY = (double)height/imageHeight; AffineTransform scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY); AffineTransformOp bilinearScaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR); return bilinearScaleOp.filter( image, new BufferedImage(width, height, image.getType())); }*/ public BufferedImage ScaleImage(BufferedImage bi, int maxWidth, int maxHeight) { double originalWidth = bi.getWidth() * 1.0; double originalHeight = bi.getHeight() * 1.0; double widthRatio = (maxWidth * 1.0) / originalWidth; double heightRatio = (maxHeight * 1.0) / originalHeight; double newImageRatio = 0; if (widthRatio < heightRatio) { newImageRatio = widthRatio; } else { newImageRatio = heightRatio; } BufferedImage bdest = new BufferedImage((int) (originalWidth * newImageRatio), (int) (originalHeight * newImageRatio), BufferedImage.TYPE_INT_RGB); Graphics2D g = bdest.createGraphics(); AffineTransform at = AffineTransform.getScaleInstance(newImageRatio, newImageRatio); g.drawRenderedImage(bi, at); return bdest; }
From source file:de.bund.bfr.knime.chart.ChartUtils.java
public static ImagePortObject getImage(JFreeChart chart, boolean asSvg, int width, int height) { if (asSvg) {/* ww w .j ava2 s . co m*/ SVGDocument document = (SVGDocument) new SVGDOMImplementation().createDocument(null, "svg", null); SVGGraphics2D g = new SVGGraphics2D(document); g.setSVGCanvasSize(new Dimension(width, height)); if (chart != null) { chart.draw(g, new Rectangle2D.Double(0, 0, width, height)); } g.dispose(); document.replaceChild(g.getRoot(), document.getDocumentElement()); return new ImagePortObject(new SvgImageContent(document), new ImagePortObjectSpec(SvgCell.TYPE)); } else { try { BufferedImage img = chart != null ? chart.createBufferedImage(width, height) : new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); return new ImagePortObject(new PNGImageContent(ChartUtilities.encodeAsPNG(img)), new ImagePortObjectSpec(PNGImageContent.TYPE)); } catch (IOException e) { e.printStackTrace(); return null; } } }
From source file:org.jfree.data.general.HeatMapUtilities.java
/** * Creates an image that displays the values from the specified dataset. * * @param dataset the dataset (<code>null</code> not permitted). * @param paintScale the paint scale for the z-values (<code>null</code> * not permitted).// ww w . ja v a2 s. c o m * * @return A buffered image. */ public static BufferedImage createHeatMapImage(HeatMapDataset dataset, PaintScale paintScale) { ParamChecks.nullNotPermitted(dataset, "dataset"); ParamChecks.nullNotPermitted(paintScale, "paintScale"); int xCount = dataset.getXSampleCount(); int yCount = dataset.getYSampleCount(); BufferedImage image = new BufferedImage(xCount, yCount, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = image.createGraphics(); for (int xIndex = 0; xIndex < xCount; xIndex++) { for (int yIndex = 0; yIndex < yCount; yIndex++) { double z = dataset.getZValue(xIndex, yIndex); Paint p = paintScale.getPaint(z); g2.setPaint(p); g2.fillRect(xIndex, yCount - yIndex - 1, 1, 1); } } return image; }
From source file:com.compomics.pepshell.view.statistics.CleavingProbabilityPane.java
@Override public void setGraphData(PepshellProtein aPepshellProtein) { //obligatory checks if (aPepshellProtein != null && experiment.getProteins().contains(aPepshellProtein)) { if (aPepshellProtein != currentPepshellProtein) { //TODO: run this outside of the gui thread currentPepshellProtein = experiment.getProteins() .get(experiment.getProteins().indexOf(aPepshellProtein)); XYSeriesCollection xYSeriesCollection = new XYSeriesCollection(); fillSeries(currentPepshellProtein).forEach(xYSeriesCollection::addSeries); JFreeChart CPDTchart = ChartFactory.createXYLineChart("probability of cleaving", "aminoacids of " + currentPepshellProtein.getVisibleAccession(), "probability", xYSeriesCollection, PlotOrientation.VERTICAL, false, true, false); prettifyChart(CPDTchart);/*from w ww .j a v a 2s . co m*/ CPDTchart.getXYPlot().getRangeAxis().setLowerBound(cutoff - 0.05); for (int i = 0; i < CPDTchart.getXYPlot().getSeriesCount(); i++) { CPDTchart.getXYPlot().getRenderer().setSeriesStroke(i, new BasicStroke(5)); } if (!aPepshellProtein.getDomains().isEmpty()) { CPDTchart.setBackgroundImageAlpha(0.18f); CPDTchart.getXYPlot().getDomainAxis().setRange(0, aPepshellProtein.getProteinSequence().length()); BufferedImage anImage = new BufferedImage(this.getHeight(), this.getWidth(), BufferedImage.TYPE_INT_ARGB); for (FeatureWithLocation aDomain : aPepshellProtein.getDomains()) { anImage.getGraphics().drawRect(aDomain.getStartPosition(), 0, aDomain.getEndPosition(), this.getHeight()); } CPDTchart.setBackgroundImage(anImage); } chart.setChart(CPDTchart); } } else { chart.setChart(null); this.getGraphics().drawString("missing data", 0, 0); } }
From source file:com.igormaznitsa.sciareto.ui.UiUtils.java
@Nonnull public static Image makeBadgedRightBottom(@Nonnull final Image base, @Nonnull final Image badge) { final int width = Math.max(base.getWidth(null), badge.getWidth(null)); final int height = Math.max(base.getHeight(null), badge.getHeight(null)); final BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); final Graphics gfx = result.getGraphics(); try {// www. jav a2s . c o m gfx.drawImage(base, (width - base.getWidth(null)) / 2, (height - base.getHeight(null)) / 2, null); gfx.drawImage(badge, width - badge.getWidth(null) - 1, height - badge.getHeight(null) - 1, null); } finally { gfx.dispose(); } return result; }
From source file:org.jfree.chart.demo.ChartTiming3.java
/** * Runs the test.//from www . ja v a 2 s .c o m */ public void run() { this.finished = false; // create a dataset... final XYSeries series = new XYSeries("Random Data"); for (int i = 0; i < 1440; i++) { final double x = Math.random(); final double y = Math.random(); series.add(x, y); } final XYDataset data = new XYSeriesCollection(series); // create a scatter chart... final boolean withLegend = true; final JFreeChart chart = ChartFactory.createScatterPlot("Scatter plot timing", "X", "Y", data, PlotOrientation.VERTICAL, withLegend, false, false); final XYPlot plot = chart.getXYPlot(); plot.setRenderer(new XYDotRenderer()); final BufferedImage image = new BufferedImage(400, 300, BufferedImage.TYPE_INT_RGB); final Graphics2D g2 = image.createGraphics(); final Rectangle2D chartArea = new Rectangle2D.Double(0, 0, 400, 300); // set up the timer... final Timer timer = new Timer(10000, this); timer.setRepeats(false); int count = 0; timer.start(); while (!this.finished) { chart.draw(g2, chartArea, null, null); System.out.println("Charts drawn..." + count); if (!this.finished) { count++; } } System.out.println("DONE"); }
From source file:org.n52.server.sos.generator.DiagramGenerator.java
/** * Creates a time series chart diagram and writes it to the OutputStream. * //from w w w.j av a 2s .c o m * @param entireCollMap * @param options * @param out * @throws OXFException * @throws IOException */ public void producePresentation(Map<String, OXFFeatureCollection> entireCollMap, DesignOptions options, FileOutputStream out, boolean compress) throws OXFException, IOException { // render features: int width = options.getWidth(); int height = options.getHeight(); Calendar begin = Calendar.getInstance(); begin.setTimeInMillis(options.getBegin()); Calendar end = Calendar.getInstance(); end.setTimeInMillis(options.getEnd()); DiagramRenderer renderer = new DiagramRenderer(false); JFreeChart diagramChart = renderer.renderChart(entireCollMap, options, begin, end, compress); diagramChart.removeLegend(); // draw chart into image: BufferedImage diagramImage = new BufferedImage(width, height, TYPE_INT_RGB); Graphics2D chartGraphics = diagramImage.createGraphics(); chartGraphics.setColor(Color.white); chartGraphics.fillRect(0, 0, width, height); diagramChart.draw(chartGraphics, new Rectangle2D.Float(0, 0, width, height)); JPEGEncodeParam p = new JPEGEncodeParam(); p.setQuality(1f); ImageEncoder encoder = ImageCodec.createImageEncoder("jpeg", out, p); encoder.encode(diagramImage); }
From source file:game.com.HandleUploadGameThumbServlet.java
public static BufferedImage resizeImage(final Image image, int width, int height) { final BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); final Graphics2D graphics2D = bufferedImage.createGraphics(); graphics2D.setComposite(AlphaComposite.Src); //below three lines are for RenderingHints for better image quality at cost of higher processing time graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics2D.drawImage(image, 0, 0, width, height, null); graphics2D.dispose();//ww w. j a v a 2 s.c om return bufferedImage; }