List of usage examples for java.awt.image BufferedImage BufferedImage
public BufferedImage(int width, int height, int imageType)
From source file:com.foudroyantfactotum.mod.fousarchive.midi.generation.MidiImageGeneration.java
public ImmutablePair<String, BufferedImage> buildImage() throws InterruptedException, ExecutionException { final Future<String> name = pool.submit(new LineProcessor(imgX)); final BufferedImage mdbf = new BufferedImage(imgX, imgY, BufferedImage.TYPE_BYTE_GRAY); final Graphics g = mdbf.getGraphics(); g.setColor(Color.BLACK);//from ww w . ja v a 2 s .com g.fillRect(0, 0, imgX, imgY); g.setColor(Color.WHITE); for (Line l = lines.take(); l != TERMINATE; l = lines.take()) { g.drawLine(l.note, (int) Math.round(l.tickStart * imgY), l.note, (int) Math.round(l.tickEnd * imgY)); } pool.shutdown(); g.dispose(); return ImmutablePair.of(name.get(), mdbf); }
From source file:AttributesApp.java
public AttributesApp() { setBackground(Color.lightGray); setSize(500, 200);// ww w . jav a2 s . c om attribString = new AttributedString(text); GeneralPath star = new GeneralPath(); star.moveTo(0, 0); star.lineTo(10, 30); star.lineTo(-10, 10); star.lineTo(10, 10); star.lineTo(-10, 30); star.closePath(); GraphicAttribute starShapeAttr = new ShapeGraphicAttribute(star, GraphicAttribute.TOP_ALIGNMENT, false); attribString.addAttribute(TextAttribute.CHAR_REPLACEMENT, starShapeAttr, 0, 1); attribString.addAttribute(TextAttribute.FOREGROUND, new Color(255, 255, 0), 0, 1); int index = text.indexOf("Java Source"); attribString.addAttribute(TextAttribute.FOREGROUND, Color.blue, index, index + 7); Font font = new Font("sanserif", Font.ITALIC, 40); attribString.addAttribute(TextAttribute.FONT, font, index, index + 7); loadImage(); BufferedImage bimage = new BufferedImage(image.getWidth(this), image.getHeight(this), BufferedImage.TYPE_INT_ARGB); Graphics2D big = bimage.createGraphics(); big.drawImage(image, null, this); GraphicAttribute javaImageAttr = new ImageGraphicAttribute(bimage, GraphicAttribute.TOP_ALIGNMENT, 0, 0); index = text.indexOf("Java"); attribString.addAttribute(TextAttribute.CHAR_REPLACEMENT, javaImageAttr, index - 1, index); font = new Font("serif", Font.BOLD, 60); attribString.addAttribute(TextAttribute.FONT, font, index, index + 4); attribString.addAttribute(TextAttribute.FOREGROUND, new Color(243, 63, 163), index, index + 4); // Start and end indexes. index = text.indexOf("source"); attribString.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, index, index + 2); index = text.indexOf("and support"); font = new Font("sanserif", Font.ITALIC, 40); attribString.addAttribute(TextAttribute.FONT, font, index, index + 10); attribString.addAttribute(TextAttribute.FOREGROUND, Color.white, index, index + 2); // Start and end indexes. attribString.addAttribute(TextAttribute.FOREGROUND, Color.blue, index + 3, index + 10); // Start and end indexes. }
From source file:ImageTransferTest.java
public ImageTransferFrame() { setTitle("ImageTransferTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); label = new JLabel(); image = new BufferedImage(DEFAULT_WIDTH, DEFAULT_HEIGHT, BufferedImage.TYPE_INT_ARGB); Graphics g = image.getGraphics(); g.setColor(Color.WHITE);//from ww w . j av a2s . com g.fillRect(0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT); g.setColor(Color.RED); g.fillOval(DEFAULT_WIDTH / 4, DEFAULT_WIDTH / 4, DEFAULT_WIDTH / 2, DEFAULT_HEIGHT / 2); label.setIcon(new ImageIcon(image)); add(new JScrollPane(label), BorderLayout.CENTER); JPanel panel = new JPanel(); JButton copyButton = new JButton("Copy"); panel.add(copyButton); copyButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { copy(); } }); JButton pasteButton = new JButton("Paste"); panel.add(pasteButton); pasteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { paste(); } }); add(panel, BorderLayout.SOUTH); }
From source file:at.gv.egiz.pdfas.common.utils.ImageUtils.java
public static BufferedImage convertRGBAToIndexed(BufferedImage src) { BufferedImage dest = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_BYTE_INDEXED); Graphics g = dest.getGraphics(); g.setColor(new Color(231, 20, 189)); g.fillRect(0, 0, dest.getWidth(), dest.getHeight()); // fill with a // hideous color // and make it // transparent dest = makeTransparent(dest, 0, 0);// ww w. j ava 2s.c o m dest.createGraphics().drawImage(src, 0, 0, null); return dest; }
From source file:maltcms.ui.fileHandles.serialized.SeriesPaintComboBoxRenderer.java
private BufferedImage createColorImage(Paint p) { BufferedImage bi = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = bi.createGraphics(); g2.setPaint(p);//from w w w . ja va 2 s . c om g2.fillRect(0, 0, bi.getWidth(), bi.getHeight()); return bi; }
From source file:org.gbif.portal.web.util.ChartUtils.java
/** * Writes out the image using the supplied file name. * //from w w w . ja v a 2 s.c om * @param legend * @param fileName * @return */ public static String writePieChartImageToTempFile(Map<String, Double> legend, String fileName) { String filePath = System.getProperty(tmpDirSystemProperty) + File.separator + fileName + defaultExtension; File fileToCheck = new File(filePath); if (fileToCheck.exists()) { return fileName + defaultExtension; } final DefaultPieDataset data = new DefaultPieDataset(); Set<String> keys = legend.keySet(); for (String key : keys) { logger.info("Adding key : " + key); data.setValue(key, legend.get(key)); } // create a pie chart... final boolean withLegend = true; final JFreeChart chart = ChartFactory.createPieChart(null, data, withLegend, false, false); PiePlot piePlot = (PiePlot) chart.getPlot(); piePlot.setLabelFont(new Font("Arial", Font.PLAIN, 10)); piePlot.setLabelBackgroundPaint(Color.WHITE); LegendTitle lt = chart.getLegend(); lt.setBackgroundPaint(Color.WHITE); lt.setWidth(300); lt.setBorder(0, 0, 0, 0); lt.setItemFont(new Font("Arial", Font.PLAIN, 11)); chart.setPadding(new RectangleInsets(0, 0, 0, 0)); chart.setBorderVisible(false); chart.setBackgroundImageAlpha(0); chart.setBackgroundPaint(Color.WHITE); chart.setBorderPaint(Color.LIGHT_GRAY); final BufferedImage image = new BufferedImage(300, 250, BufferedImage.TYPE_INT_RGB); KeypointPNGEncoderAdapter adapter = new KeypointPNGEncoderAdapter(); adapter.setQuality(1); try { adapter.encode(image); } catch (IOException e) { logger.error(e.getMessage(), e); } final Graphics2D g2 = image.createGraphics(); g2.setFont(new Font("Arial", Font.PLAIN, 11)); final Rectangle2D chartArea = new Rectangle2D.Double(0, 0, 300, 250); // draw chart.draw(g2, chartArea, null, null); try { FileOutputStream fOut = new FileOutputStream(fileToCheck); ChartUtilities.writeChartAsPNG(fOut, chart, 300, 250); return fileToCheck.getName(); } catch (IOException e) { logger.error(e.getMessage(), e); return null; } }
From source file:RGBGrayFilter.java
/** * Returns an icon with a disabled appearance. This method is used * to generate a disabled icon when one has not been specified. * * @param component the component that will display the icon, may be null. * @param icon the icon to generate disabled icon from. * @return disabled icon, or null if a suitable icon can not be generated. *///from w w w .j ava 2 s. c o m public static Icon getDisabledIcon(JComponent component, Icon icon) { if ((icon == null) || (component == null) || (icon.getIconWidth() == 0) || (icon.getIconHeight() == 0)) { return null; } Image img; if (icon instanceof ImageIcon) { img = ((ImageIcon) icon).getImage(); } else { img = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); icon.paintIcon(component, img.getGraphics(), 0, 0); } ImageProducer producer = new FilteredImageSource(img.getSource(), new RGBGrayFilter()); return new ImageIcon(component.createImage(producer)); }
From source file:com.frostwire.gui.library.LibraryCoverArt.java
public LibraryCoverArt() { background = new BufferedImage(350, 350, BufferedImage.TYPE_INT_ARGB); defaultCoverArt = GUIMediator.getThemeImage("default_cover_art").getImage(); setFile(null);/* w ww . j a va2 s . c o m*/ addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { updateTheme(); } }); ThemeMediator.addThemeObserver(this); }
From source file:com.l1j5.web.common.utils.ImageUtils.java
public static void getGifImageThumbnail(BufferedInputStream stream_file, String save, String type, int w, int h) {/*from w w w . j a v a 2s . c o m*/ GifDecoder dec = new GifDecoder(); AnimatedGifEncoder enc = new AnimatedGifEncoder(); dec.read(stream_file); int cnt = dec.getFrameCount(); int delay = 0; int width = 0; int height = 0; try { enc.start(save); enc.setRepeat(0); for (int i = 0; i < cnt; i++) { BufferedImage frame = dec.getFrame(i); delay = dec.getDelay(i); width = frame.getWidth(); height = frame.getHeight(); if (w < width) { width = w; } if (h < height) { height = h; } BufferedImage destimg = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR); Graphics2D g = destimg.createGraphics(); g.drawImage(frame, 0, 0, width, height, null); enc.setDelay(delay); enc.addFrame(destimg); } enc.finish(); } catch (Exception ex) { log.error(ex); } }
From source file:edu.stanford.muse.webapp.HTMLToImage.java
/** * Convert an HTML page at the specified URL into an image who's data is * written to the provided output stream. * * @param url URL to the page that is to be imaged. * @param os An output stream that is to be opened for writing. Image * data will be written to the provided stream. The stream * will not be closed under any circumstances by this method. * @param width The desired width of the image that will be created. * @param height The desired height of the image that will be created. * * @returns true if the page at the provided URL was loaded, converted to an * image, and the image data has been written to the output stream, * false if an error has ocurred along the way. * * @throws HTMLImagerException if an error has ocurred. *///from w ww.j a va2 s. c o m public static boolean image(String url, OutputStream os, int width, int height) { if (log.isDebugEnabled()) log.debug("Imaging url '" + url + "'."); boolean successful = false; try { HttpClient httpClient = new HttpClient(); GetMethod getMethod = new GetMethod(url); httpClient.executeMethod(getMethod); int httpStatus = getMethod.getStatusCode(); if (httpStatus == HttpServletResponse.SC_OK) { Tidy tidy = new Tidy(); tidy.setQuiet(true); tidy.setXHTML(true); tidy.setHideComments(true); tidy.setInputEncoding("UTF-8"); tidy.setOutputEncoding("UTF-8"); tidy.setShowErrors(0); tidy.setShowWarnings(false); Document doc = tidy.parseDOM(getMethod.getResponseBodyAsStream(), null); if (doc != null) { BufferedImage buf = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = (Graphics2D) buf.getGraphics(); Graphics2DRenderer renderer = new Graphics2DRenderer(); SharedContext context = renderer.getSharedContext(); UserAgentCallback userAgent = new HTMLImagerUserAgent(url); context.setUserAgentCallback(userAgent); context.setNamespaceHandler(new XhtmlNamespaceHandler()); renderer.setDocument(doc, url); renderer.layout(graphics, new Dimension(width, height)); renderer.render(graphics); graphics.dispose(); /* JPEGEncodeParam param = JPEGCodec.getDefaultJPEGEncodeParam( buf ); param.setQuality( (float)1.0, false ); JPEGImageEncoder imageEncoder = JPEGCodec.createJPEGEncoder( os, param ); imageEncoder.encode( buf ); */ successful = true; } else { if (log.isDebugEnabled()) log.debug("Unable to image URL '" + url + "'. The HTML that was returned could not be tidied."); } } else { if (log.isDebugEnabled()) log.debug("Unable to image URL '" + url + "'. Server returned status code '" + httpStatus + "'."); } } catch (Exception e) { throw new RuntimeException("Unable to image URL '" + url + "'.", e); } return successful; }