List of usage examples for java.awt.image BufferedImage TYPE_INT_ARGB
int TYPE_INT_ARGB
To view the source code for java.awt.image BufferedImage TYPE_INT_ARGB.
Click Source Link
From source file:eu.udig.style.advanced.utils.Utilities.java
/** * Creates an image from a set of {@link RuleWrapper}s. * //from ww w . java 2 s. c o m * @param rulesWrapperList the list of rules wrapper. * @param width the image width. * @param height the image height. * @return the new created {@link BufferedImage}. */ public static BufferedImage polygonRulesWrapperToImage(final List<RuleWrapper> rulesWrapperList, int width, int height) { BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = image.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); for (RuleWrapper rule : rulesWrapperList) { BufferedImage tmpImage = Utilities.polygonRuleWrapperToImage(rule, width, height); g2d.drawImage(tmpImage, 0, 0, null); } g2d.dispose(); return image; }
From source file:com.pronoiahealth.olhie.server.services.BookCoverImageService.java
/** * //from w w w. j a va2s .c o m * @param book * @param category * @param cover * @param logo * @param author * @return * @throws Exception */ public String createDefaultFrontCoverEncoded(Book book, BookCategory category, BookCover cover, byte[] logo, String authorName) throws Exception { return createFrontCoverEncoded(book.getCoverName(), logo, authorName, book.getBookTitle(), category.getColor(), cover.getAuthorTextColor(), cover.getCoverTitleTextColor(), 300, 400, BufferedImage.TYPE_INT_ARGB, ImageFormat.IMAGE_FORMAT_PNG, 128); }
From source file:net.java.sip.communicator.impl.osdependent.jdic.SystrayServiceJdicImpl.java
private BufferedImage createOverlayImage(String text) { int size = 16; BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //background// w ww . ja v a2 s . c o m g.setPaint(new Color(0, 0, 0, 102)); g.fillRoundRect(0, 0, size, size, size, size); //filling int mainRadius = 14; g.setPaint(new Color(255, 98, 89)); g.fillRoundRect(size / 2 - mainRadius / 2, size / 2 - mainRadius / 2, mainRadius, mainRadius, size, size); //text Font font = g.getFont(); g.setFont(new Font(font.getName(), Font.BOLD, 9)); FontMetrics fontMetrics = g.getFontMetrics(); int textWidth = fontMetrics.stringWidth(text); g.setColor(Color.white); g.drawString(text, size / 2 - textWidth / 2, size / 2 - fontMetrics.getHeight() / 2 + fontMetrics.getAscent()); return image; }
From source file:org.jcurl.demo.tactics.JCurlShotPlanner.java
private static void renderPng(final Container src, final File dst) throws IOException { final BufferedImage img = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_ARGB); final Graphics g = img.getGraphics(); try {// ww w .j a va 2s .c o m // SwingUtilities.paintComponent(g, src, src.getBounds(), null); src.paintAll(g); } finally { g.dispose(); } ImageIO.write(img, "png", dst); }
From source file:fr.ens.transcriptome.corsen.gui.qt.ResultGraphs.java
/** * Create a scatter plot//from w w w . java 2s . c o m * @param particles Particle data to use * @param title Title of the graph * @return a QImage */ public QImage createScatterPlot(final Particles3D particles, final String title, final String unit) { if (particles == null) return null; List<Particle3D> pars = particles.getParticles(); final int count = pars.size(); final double[][] data = new double[2][]; data[0] = new double[count]; data[1] = new double[count]; int i = 0; for (Particle3D p : pars) { data[0][i] = p.getIntensity(); data[1][i] = p.getVolume(); i++; } DefaultXYDataset xydataset = new DefaultXYDataset(); xydataset.addSeries("data", data); JFreeChart chart = ChartFactory.createScatterPlot(title, "Intensity", "Volume" + unitLegendCude(unit), xydataset, PlotOrientation.VERTICAL, false, true, false); addTransparency(chart); XYPlot xyplot = (XYPlot) chart.getPlot(); XYDotRenderer xydotrenderer = new XYDotRenderer(); xydotrenderer.setDotWidth(2); xydotrenderer.setDotHeight(2); xyplot.setRenderer(xydotrenderer); NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis(); numberaxis.setAutoRangeIncludesZero(false); final BufferedImage image = chart.createBufferedImage(this.width, this.height, BufferedImage.TYPE_INT_ARGB, null); return new QImage(toByte(image.getData().getDataBuffer()), this.width, this.height, QImage.Format.Format_ARGB32); }
From source file:fr.amap.commons.javafx.chart.ChartViewer.java
/** * A handler for the export to PNG option in the context menu. */// w w w . ja v a2 s .c om private void handleExportToPNG() { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Export to PNG"); fileChooser.setSelectedExtensionFilter( new FileChooser.ExtensionFilter("Portable Network Graphics (PNG)", "png")); File file = fileChooser.showSaveDialog(stage); if (file != null) { try { CanvasPositionsAndSize canvasPositionAndSize = getCanvasPositionAndSize(); BufferedImage image = new BufferedImage((int) canvasPositionAndSize.totalWidth, (int) canvasPositionAndSize.totalHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = image.createGraphics(); int index = 0; for (ChartCanvas canvas : chartCanvasList) { Rectangle2D rectangle2D = canvasPositionAndSize.positionsAndSizes.get(index); ((Drawable) canvas.chart).draw(g2, new Rectangle((int) rectangle2D.getX(), (int) rectangle2D.getY(), (int) rectangle2D.getWidth(), (int) rectangle2D.getHeight())); index++; } try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) { ImageIO.write(image, "png", out); } } catch (IOException ex) { // FIXME: show a dialog with the error } } }
From source file:com.simiacryptus.util.Util.java
/** * Resize buffered image.//from ww w . j a v a2 s . c o m * * @param image the image * @return the buffered image */ @Nullable public static BufferedImage resize(@Nullable final BufferedImage image) { if (null == image) return image; final int width = Math.min(image.getWidth(), 800); if (width == image.getWidth()) return image; final int height = image.getHeight() * width / image.getWidth(); @javax.annotation.Nonnull final BufferedImage rerender = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); final Graphics gfx = rerender.getGraphics(); @javax.annotation.Nonnull final RenderingHints hints = new RenderingHints(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); ((Graphics2D) gfx).setRenderingHints(hints); gfx.drawImage(image, 0, 0, rerender.getWidth(), rerender.getHeight(), null); return rerender; }
From source file:com.pronoiahealth.olhie.server.services.BookCoverImageService.java
public byte[] createDefaultFrontCover(Book book, BookCategory category, BookCover cover, byte[] logo, String authorName) throws Exception { return createFrontCover(book.getCoverName(), logo, authorName, book.getBookTitle(), category.getColor(), cover.getAuthorTextColor(), cover.getCoverTitleTextColor(), 300, 400, BufferedImage.TYPE_INT_ARGB, ImageFormat.IMAGE_FORMAT_PNG, 128); }
From source file:org.apache.batchee.tools.maven.doc.DiagramGenerator.java
private void saveView(final Dimension currentSize, final Dimension desiredSize, final String name, final VisualizationViewer<Node, Edge> viewer) { BufferedImage bi = new BufferedImage(currentSize.width, currentSize.height, BufferedImage.TYPE_INT_ARGB); final Graphics2D g = bi.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); final boolean db = viewer.isDoubleBuffered(); viewer.setDoubleBuffered(false);//from ww w .j ava2 s.co m viewer.paint(g); viewer.setDoubleBuffered(db); if (!currentSize.equals(desiredSize)) { final double xFactor = desiredSize.width * 1. / currentSize.width; final double yFactor = desiredSize.height * 1. / currentSize.height; final double factor = Math.min(xFactor, yFactor); info("optimal size is (" + currentSize.width + ", " + currentSize.height + ")"); info("scaling with a factor of " + factor); final AffineTransform tx = new AffineTransform(); tx.scale(factor, factor); final AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR); BufferedImage biNew = new BufferedImage((int) (bi.getWidth() * factor), (int) (bi.getHeight() * factor), bi.getType()); bi = op.filter(bi, biNew); } g.dispose(); OutputStream os = null; try { final File file = new File(output, (outputFileName != null ? outputFileName : name) + "." + format); os = new FileOutputStream(file); if (!ImageIO.write(bi, format, os)) { throw new IllegalStateException("can't save picture " + name + "." + format); } info("Saved " + file.getAbsolutePath()); } catch (final IOException e) { throw new IllegalStateException("can't save the diagram", e); } finally { if (os != null) { try { os.flush(); os.close(); } catch (final IOException e) { // no-op } } } }
From source file:de.mprengemann.intellij.plugin.androidicons.images.ImageUtils.java
private static BufferedImage rescaleBorder(BufferedImage image, int targetWidth, int targetHeight) { if (targetWidth == 0) { targetWidth = 1;/* www. j a va 2 s . c o m*/ } if (targetHeight == 0) { targetHeight = 1; } if (targetHeight > 1 && targetWidth > 1) { throw new Wrong9PatchException(); } int w = image.getWidth(); int h = image.getHeight(); int[] data = image.getRGB(0, 0, w, h, null, 0, w); int[] newData = new int[targetWidth * targetHeight]; for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { newData[y * targetWidth + x] = 0x00; } } List<Integer> startPositions = new ArrayList<Integer>(); List<Integer> endPositions = new ArrayList<Integer>(); boolean inBlock = false; if (targetHeight == 1) { for (int x = 0; x < w; x++) { if ((0xff000000 & data[x]) != 0) { if (!inBlock) { inBlock = true; startPositions.add(x); } } else if (inBlock) { endPositions.add(x - 1); inBlock = false; } } if (inBlock) { endPositions.add(w - 1); } } else { for (int y = 0; y < h; y++) { if ((0xff000000 & data[y]) != 0) { if (!inBlock) { inBlock = true; startPositions.add(y); } } else if (inBlock) { endPositions.add(y - 1); inBlock = false; } } if (inBlock) { endPositions.add(h - 1); } } try { SplineInterpolator interpolator = new SplineInterpolator(); PolynomialSplineFunction function = interpolator.interpolate( new double[] { 0f, 1f, Math.max(w - 1, h - 1) }, new double[] { 0f, 1f, Math.max(targetHeight - 1, targetWidth - 1) }); for (int i = 0; i < startPositions.size(); i++) { int start = startPositions.get(i); int end = endPositions.get(i); for (int j = (int) function.value(start); j <= (int) function.value(end); j++) { newData[j] = 0xff000000; } } BufferedImage img = UIUtil.createImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_ARGB); img.setRGB(0, 0, targetWidth, targetHeight, newData, 0, targetWidth); return img; } catch (Exception e) { Logger.getInstance(ImageUtils.class).error("resizeBorder", e); } return null; }