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:com.igormaznitsa.jhexed.swing.editor.ui.dialogs.hexeditors.DialogEditSVGImageValue.java
private void buttonLoadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonLoadActionPerformed final JFileChooser openDialog = new JFileChooser(lastOpenedFile); openDialog.setDialogTitle("Select SVG file"); openDialog.setAcceptAllFileFilterUsed(true); openDialog.setFileFilter(Utils.SVG_FILE_FILTER); if (openDialog.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { lastOpenedFile = openDialog.getSelectedFile(); try {//from w ww . ja v a 2 s .com final SVGImage img = new SVGImage(lastOpenedFile); this.value.setImage(img); this.panelPreview.removeAll(); this.panelPreview.add( new JLabel(new ImageIcon( img.rasterize(PREVIEW_SIZE, PREVIEW_SIZE, BufferedImage.TYPE_INT_ARGB))), BorderLayout.CENTER); this.panelPreview.revalidate(); this.panelPreview.repaint(); this.buttonOk.setEnabled(true); this.buttonSaveAs.setEnabled(true); } catch (IOException ex) { Log.error("Can't rasterize image [" + lastOpenedFile + ']', ex); JOptionPane.showMessageDialog(this, "Can't load the file, may be it is not a SVG file", "Can't load the file", JOptionPane.ERROR_MESSAGE); } } }
From source file:QuestionGUI.java
/** * Converts a given Image into a BufferedImage * * CREDIT//from ww w.jav a 2 s. com * https://code.google.com/p/game-engine-for-java/source/browse/src/com/gej/util/ImageTool.java#31 * * @param img The Image to be converted * @return The converted BufferedImage */ private static BufferedImage toBufferedImage(Image img) { if (img instanceof BufferedImage) { return (BufferedImage) img; } // Create a buffered image with transparency BufferedImage bimage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB); // Draw the image on to the buffered image Graphics2D bGr = bimage.createGraphics(); bGr.drawImage(img, 0, 0, null); bGr.dispose(); // Return the buffered image return bimage; }
From source file:au.org.ala.biocache.web.MapController.java
private void displayBlankImage(int width, int height, boolean useBase, HttpServletResponse response) { try {// ww w. jav a 2 s .c om response.setContentType("image/png"); BufferedImage baseImage = null; if (useBase) { baseImage = createBaseMapImage(); } else { baseImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ImageIO.write(baseImage, "png", outputStream); ServletOutputStream outStream = response.getOutputStream(); outStream.write(outputStream.toByteArray()); outStream.flush(); outStream.close(); } catch (Exception e) { logger.error("Unable to write image", e); } }
From source file:org.jtalks.jcommune.service.nontransactional.ImageConverterTest.java
@Test public void resizeIconWithWidthLessThenMinimumShouldCreateIconWidthMinimumWidth() { ImageConverter converter = ImageConverter.createConverter("ico", DEFAULT_MAX_WIDTH, DEFAULT_MAX_HEIGHT); BufferedImage image = new BufferedImage(ImageConverter.MINIMUM_ICO_WIDTH / 4, 5, BufferedImage.TYPE_INT_ARGB); image = converter.resizeImage(image, BufferedImage.TYPE_INT_ARGB); assertEquals(image.getHeight(), 5 * 4); assertEquals(image.getWidth(), ImageConverter.MINIMUM_ICO_WIDTH); }
From source file:org.jas.util.ImageUtils.java
public Image resize(Image image, int width, int height) { BufferedImage bufferedImage = (BufferedImage) image; int type = bufferedImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : bufferedImage.getType(); BufferedImage resizedImage = new BufferedImage(width, height, type); Graphics2D g = resizedImage.createGraphics(); g.setComposite(AlphaComposite.Src); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.drawImage(image, 0, 0, width, height, null); g.dispose();//from ww w .j ava2 s . c om return resizedImage; }
From source file:de.mprengemann.intellij.plugin.androidicons.images.ImageUtils.java
private static BufferedImage resizeBorder(final BufferedImage border, int targetWidth, int targetHeight) throws IOException { if (targetWidth > border.getWidth() || targetHeight > border.getHeight()) { BufferedImage endImage = rescaleBorder(border, targetWidth, targetHeight); enforceBorderColors(endImage);/*from www. ja va 2 s. c o m*/ return endImage; } int w = border.getWidth(); int h = border.getHeight(); int[] data = border.getRGB(0, 0, w, h, null, 0, w); int[] newData = new int[targetWidth * targetHeight]; float widthRatio = (float) Math.max(targetWidth - 1, 1) / (float) Math.max(w - 1, 1); float heightRatio = (float) Math.max(targetHeight - 1, 1) / (float) Math.max(h - 1, 1); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { if ((0xff000000 & data[y * w + x]) != 0) { int newX = Math.min(Math.round(x * widthRatio), targetWidth - 1); int newY = Math.min(Math.round(y * heightRatio), targetHeight - 1); newData[newY * targetWidth + newX] = data[y * w + x]; } } } BufferedImage img = UIUtil.createImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_ARGB); img.setRGB(0, 0, targetWidth, targetHeight, newData, 0, targetWidth); return img; }
From source file:com.salesmanager.core.util.ProductImageUtil.java
public BufferedImage resize(BufferedImage image, int width, int height) { int type = image.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : image.getType(); BufferedImage resizedImage = new BufferedImage(width, height, type); Graphics2D g = resizedImage.createGraphics(); g.setComposite(AlphaComposite.Src); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.drawImage(image, 0, 0, width, height, null); g.dispose();/*from w ww .j a v a2 s . c o m*/ return resizedImage; }
From source file:org.eclipse.smarthome.ui.internal.chart.defaultchartprovider.DefaultChartProvider.java
@Override public BufferedImage createChart(String serviceId, String theme, Date startTime, Date endTime, int height, int width, String items, String groups, Integer dpiValue, Boolean legend) throws ItemNotFoundException, IllegalArgumentException { logger.debug(/*from ww w. j av a2s. c o m*/ "Rendering chart: service: '{}', theme: '{}', startTime: '{}', endTime: '{}', width: '{}', height: '{}', items: '{}', groups: '{}', dpi: '{}', legend: '{}'", serviceId, theme, startTime, endTime, width, height, items, groups, dpiValue, legend); // If a persistence service is specified, find the provider, or use the default provider PersistenceService service = (serviceId == null) ? persistenceServiceRegistry.getDefault() : persistenceServiceRegistry.get(serviceId); // Did we find a service? QueryablePersistenceService persistenceService = (service instanceof QueryablePersistenceService) ? (QueryablePersistenceService) service : (QueryablePersistenceService) persistenceServiceRegistry.getAll() // .stream() // .filter(it -> it instanceof QueryablePersistenceService) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("No Persistence service found.")); int seriesCounter = 0; // get theme ChartTheme chartTheme = getChartTheme(theme); // get DPI int dpi; if (dpiValue != null && dpiValue > 0) { dpi = dpiValue; } else { dpi = DPI_DEFAULT; } // Create Chart Chart chart = new ChartBuilder().width(width).height(height).build(); // Define the time axis - the defaults are not very nice long period = (endTime.getTime() - startTime.getTime()) / 1000; String pattern = "HH:mm"; if (period <= 600) { // 10 minutes pattern = "mm:ss"; } else if (period <= 86400) { // 1 day pattern = "HH:mm"; } else if (period <= 604800) { // 1 week pattern = "EEE d"; } else { pattern = "d MMM"; } chart.getStyleManager().setDatePattern(pattern); // axis chart.getStyleManager().setAxisTickLabelsFont(chartTheme.getAxisTickLabelsFont(dpi)); chart.getStyleManager().setAxisTickLabelsColor(chartTheme.getAxisTickLabelsColor()); chart.getStyleManager().setXAxisMin(startTime.getTime()); chart.getStyleManager().setXAxisMax(endTime.getTime()); int yAxisSpacing = Math.max(height / 10, chartTheme.getAxisTickLabelsFont(dpi).getSize()); chart.getStyleManager().setYAxisTickMarkSpacingHint(yAxisSpacing); // chart chart.getStyleManager().setChartBackgroundColor(chartTheme.getChartBackgroundColor()); chart.getStyleManager().setChartFontColor(chartTheme.getChartFontColor()); chart.getStyleManager().setChartPadding(chartTheme.getChartPadding(dpi)); chart.getStyleManager().setPlotBackgroundColor(chartTheme.getPlotBackgroundColor()); float plotGridLinesDash = (float) chartTheme.getPlotGridLinesDash(dpi); float[] plotGridLinesDashArray = { plotGridLinesDash, plotGridLinesDash }; chart.getStyleManager().setPlotGridLinesStroke(new BasicStroke( (float) chartTheme.getPlotGridLinesWidth(dpi), 0, 2, 10, plotGridLinesDashArray, 0)); chart.getStyleManager().setPlotGridLinesColor(chartTheme.getPlotGridLinesColor()); // legend chart.getStyleManager().setLegendBackgroundColor(chartTheme.getLegendBackgroundColor()); chart.getStyleManager().setLegendFont(chartTheme.getLegendFont(dpi)); chart.getStyleManager().setLegendSeriesLineLength(chartTheme.getLegendSeriesLineLength(dpi)); // Loop through all the items if (items != null) { String[] itemNames = items.split(","); for (String itemName : itemNames) { Item item = itemUIRegistry.getItem(itemName); if (addItem(chart, persistenceService, startTime, endTime, item, seriesCounter, chartTheme, dpi)) { seriesCounter++; } } } // Loop through all the groups and add each item from each group if (groups != null) { String[] groupNames = groups.split(","); for (String groupName : groupNames) { Item item = itemUIRegistry.getItem(groupName); if (item instanceof GroupItem) { GroupItem groupItem = (GroupItem) item; for (Item member : groupItem.getMembers()) { if (addItem(chart, persistenceService, startTime, endTime, member, seriesCounter, chartTheme, dpi)) { seriesCounter++; } } } else { throw new ItemNotFoundException( "Item '" + item.getName() + "' defined in groups is not a group."); } } } Boolean showLegend = null; // If there are no series, render a blank chart if (seriesCounter == 0) { // always hide the legend showLegend = false; List<Date> xData = new ArrayList<Date>(); List<Number> yData = new ArrayList<Number>(); xData.add(startTime); yData.add(0); xData.add(endTime); yData.add(0); Series series = chart.addSeries("NONE", xData, yData); series.setMarker(SeriesMarker.NONE); series.setLineStyle(new BasicStroke(0f)); } // if the legend is not already hidden, check if legend parameter is supplied, or calculate a sensible value if (showLegend == null) { if (legend == null) { // more than one series, show the legend. otherwise hide it. showLegend = seriesCounter > 1; } else { // take value from supplied legend parameter showLegend = legend; } } // Legend position (top-left or bottom-left) is dynamically selected based on the data // This won't be perfect, but it's a good compromise if (showLegend) { if (legendPosition < 0) { chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW); } else { chart.getStyleManager().setLegendPosition(LegendPosition.InsideSW); } } else { // hide the whole legend chart.getStyleManager().setLegendVisible(false); } // Write the chart as a PNG image BufferedImage lBufferedImage = new BufferedImage(chart.getWidth(), chart.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D lGraphics2D = lBufferedImage.createGraphics(); chart.paint(lGraphics2D); return lBufferedImage; }
From source file:base.BasePlayer.ClusterTable.java
void addColumnGeneheader(Object column) { Object[] obj = new Object[3]; obj[0] = column;/*from ww w . j a v a 2 s .c o m*/ obj[1] = (int) geneheader.get(geneheader.size() - 1)[1] + (int) geneheader.get(geneheader.size() - 1)[2]; obj[2] = 100; geneheader.add(obj); if ((int) obj[1] + (int) obj[2] > this.getWidth()) { if (bufImage.getWidth() != 1) { if (bufImage.getWidth() < (int) obj[1] + (int) obj[2]) { bufImage = MethodLibrary.toCompatibleImage( new BufferedImage((int) width * 2, (int) height, BufferedImage.TYPE_INT_ARGB)); buf = (Graphics2D) bufImage.getGraphics(); } } this.setPreferredSize(new Dimension((int) obj[1] + (int) obj[2], this.getHeight())); this.revalidate(); } }
From source file:org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject.java
private BufferedImage applyMask(BufferedImage image, BufferedImage mask, boolean isSoft) throws IOException { if (mask == null) { return image; }/*from w w w . j ava2 s. co m*/ int width = image.getWidth(); int height = image.getHeight(); // scale mask to fit image, or image to fit mask, whichever is larger if (mask.getWidth() < width || mask.getHeight() < height) { mask = scaleImage(mask, width, height); } else if (mask.getWidth() > width || mask.getHeight() > height) { width = mask.getWidth(); height = mask.getHeight(); image = scaleImage(image, width, height); } // compose to ARGB BufferedImage masked = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); WritableRaster src = image.getRaster(); WritableRaster dest = masked.getRaster(); WritableRaster alpha = mask.getRaster(); float[] rgb = new float[4]; float[] rgba = new float[4]; float[] alphaPixel = null; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { src.getPixel(x, y, rgb); rgba[0] = rgb[0]; rgba[1] = rgb[1]; rgba[2] = rgb[2]; alphaPixel = alpha.getPixel(x, y, alphaPixel); if (isSoft) { rgba[3] = alphaPixel[0]; } else { rgba[3] = 255 - alphaPixel[0]; } dest.setPixel(x, y, rgba); } } return masked; }