List of usage examples for java.awt Graphics dispose
public abstract void dispose();
From source file:com.igormaznitsa.sciareto.ui.UiUtils.java
@Nonnull public static Image iconToImage(@Nonnull Component context, @Nullable final Icon icon) { if (icon instanceof ImageIcon) { return ((ImageIcon) icon).getImage(); }/*from ww w .ja v a2s. co m*/ final int width = icon == null ? 16 : icon.getIconWidth(); final int height = icon == null ? 16 : icon.getIconHeight(); final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); if (icon != null) { final Graphics g = image.getGraphics(); try { icon.paintIcon(context, g, 0, 0); } finally { g.dispose(); } } return image; }
From source file:components.FrameDemo2.java
protected static Image createFDImage() { //Create a 16x16 pixel image. BufferedImage bi = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB); //Draw into it. Graphics g = bi.getGraphics(); g.setColor(Color.BLACK);/*from w w w.j av a 2 s .c om*/ g.fillRect(0, 0, 15, 15); g.setColor(Color.RED); g.fillOval(5, 3, 6, 6); //Clean up. g.dispose(); //Return it. return bi; }
From source file:jshm.gui.GuiUtil.java
/** * Resize an ImageIcon to the specified size. * @param icon The ImageIcon to resize//from w ww . jav a2 s . co m * @param width The new width * @param height The new height */ public final static javax.swing.ImageIcon resizeIcon(ImageIcon icon, int width, int height) { LOG.info("Resizing to " + width + "x" + height); Image img = icon.getImage(); BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics g = bi.createGraphics(); g.drawImage(img, 0, 0, width, height, null); g.dispose(); return new javax.swing.ImageIcon(bi); }
From source file:FrameDemo2.java
protected static Image createFDImage() { // Create a 16x16 pixel image. BufferedImage bi = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB); // Draw into it. Graphics g = bi.getGraphics(); g.setColor(Color.BLACK);//from w w w . j a v a 2 s . c o m g.fillRect(0, 0, 15, 15); g.setColor(Color.RED); g.fillOval(5, 3, 6, 6); // Clean up. g.dispose(); // Return it. return bi; }
From source file:org.jfree.experimental.swt.SWTUtils.java
/** * Converts an AWT image to SWT.//from ww w.j av a2 s . c o m * * @param image the image (<code>null</code> not permitted). * * @return Image data. */ public static ImageData convertAWTImageToSWT(Image image) { ParamChecks.nullNotPermitted(image, "image"); int w = image.getWidth(null); int h = image.getHeight(null); if (w == -1 || h == -1) { return null; } BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.drawImage(image, 0, 0, null); g.dispose(); return convertToSWT(bi); }
From source file:de.darkblue.bongloader2.utils.ToolBox.java
public static BufferedImage grayScale(BufferedImage image) { BufferedImage newImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_GRAY); Graphics g = newImage.getGraphics(); g.drawImage(image, 0, 0, null);//from ww w . jav a 2 s . c o m g.dispose(); return newImage; }
From source file:com.boundlessgeo.geoserver.api.controllers.ThumbnailController.java
/** * Utility method for scaling thumbnails. Scales byte[] image by a scale factor. * Optionally crops images to square.//from ww w . j a va2 s. com * @param src RenderedImage containing the input image * @param scale Scale amount * @param square Boolean flag to crop to a square image * @return RenderedImage containing the transformed image * @throws IOException */ public static BufferedImage scaleImage(BufferedImage image, double scale, boolean square) throws IOException { int sx = 0, sy = 0; int swidth = image.getWidth(); int sheight = image.getHeight(); if (square) { if (image.getHeight() > image.getWidth()) { sy = (int) ((image.getHeight() - image.getWidth()) / 2.0); sheight = swidth; } else if (image.getHeight() < image.getWidth()) { sx = (int) ((image.getWidth() - image.getHeight()) / 2.0); swidth = sheight; } } int width = (int) (swidth * scale); int height = (int) (sheight * scale); BufferedImage scaled = new BufferedImage(image.getColorModel(), image.getRaster().createCompatibleWritableRaster(width, height), image.isAlphaPremultiplied(), null); Graphics g = scaled.getGraphics(); g.drawImage(image, 0, 0, width, height, sx, sy, sx + swidth, sy + sheight, null); g.dispose(); return scaled; }
From source file:com.igormaznitsa.sciareto.ui.UiUtils.java
@Nonnull public static Image makeBadgedRightTop(@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 {//from w ww .j ava 2 s . 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, 1, null); } finally { gfx.dispose(); } return result; }
From source file:org.esa.nest.dat.views.polarview.PolarCanvas.java
private static void paintComponents(Container c, Graphics g) { if (!c.isShowing()) return;//from w ww.j ava2s . c om final int ncomponents = c.getComponentCount(); final Rectangle clip = g.getClipBounds(); int i = ncomponents - 1; while (i >= 0) { final Component component[] = c.getComponents(); final Component comp = component[i]; if (comp == null || !comp.isVisible()) continue; final Rectangle bounds = comp.getBounds(); Rectangle cr; if (clip == null) cr = new Rectangle(bounds); else cr = bounds.intersection(clip); if (cr.isEmpty()) continue; final Graphics cg = g.create(); cg.setClip(cr); cg.translate(bounds.x, bounds.y); try { comp.paint(cg); } catch (Throwable e) { // } cg.dispose(); i--; } }
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 {//w ww . j a va 2s .com 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; }