List of usage examples for java.awt Image getWidth
public abstract int getWidth(ImageObserver observer);
From source file:Util.java
/** * Converts an Image to a BufferedImage/* ww w . j a va 2s .c o m*/ */ public static BufferedImage convertToBufferedImg(Image im) { BufferedImage bi = new BufferedImage(im.getWidth(null), im.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics bg = bi.getGraphics(); bg.drawImage(im, 0, 0, null); bg.dispose(); return bi; }
From source file:Main.java
public static Image resizeToWidth(Image image, int w) { int h = image.getHeight(null) * w / image.getWidth(null); Image newimg = image.getScaledInstance(w, h, java.awt.Image.SCALE_SMOOTH); // scale it the smooth way return newimg; }
From source file:Main.java
public static Image merge(Image left, Image right) { BufferedImage merged = new BufferedImage(left.getWidth(null) + right.getWidth(null), left.getHeight(null), BufferedImage.TYPE_INT_RGB); Graphics2D g = (Graphics2D) merged.getGraphics(); g.drawImage(left, 0, 0, null);// ww w. jav a2s.com g.drawImage(right, left.getWidth(null), 0, null); return merged; }
From source file:Main.java
/** * Creates a tray icon which uses the best matching icon from the specified list of icons. The icon list must be * sorted from smallest to largest image. The tray icon is NOT yet added to the system tray. The calling code must * do this when needed.//from w ww.j ava 2s.com * * @param icons * The list of icons to choose from * @return The tray icon */ public static TrayIcon createTrayIcon(final List<Image> icons) { final SystemTray systemTray = SystemTray.getSystemTray(); final int trayIconWidth = systemTray.getTrayIconSize().width; Image useIcon = null; for (final Image icon : icons) { if (icon.getWidth(null) >= trayIconWidth) { useIcon = icon; break; } } if (useIcon == null) { useIcon = icons.get(icons.size() - 1); } final TrayIcon trayIcon = new TrayIcon(useIcon); trayIcon.setImageAutoSize(true); return trayIcon; }
From source file:ImageUtil.java
/** * Creates and returns a buffered version of the specified image. * * @param image the image to create a buffered image for * @return a buffered image based on the specified image *//* ww w .j a v a2s. c om*/ public static BufferedImage getBufferedImage(Image image) { BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics g = bufferedImage.getGraphics(); g.drawImage(image, 0, 0, null); return bufferedImage; }
From source file:Main.java
public static BufferedImage asCompatibleImage(Image img) { BufferedImage ret = defaultScreenDeviceConfiguration().createCompatibleImage(img.getWidth(null), img.getHeight(null));//from www . java 2s. c o m Graphics2D gc = ret.createGraphics(); gc.drawImage(img, 0, 0, null); gc.dispose(); return ret; }
From source file:Main.java
public static BufferedImage highlightRegions(Image img, int[][] regions, int regionId, Color fgColour) { BufferedImage canvas = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = canvas.createGraphics(); g2d.drawImage(img, 0, 0, null);/* ww w .j a va 2 s .c o m*/ g2d.setColor(fgColour); for (int y = 0; y < regions.length; y++) { for (int x = 0; x < regions[y].length; x++) { if (regions[y][x] == regionId) { g2d.drawRect(x, y, 1, 1); } } } return canvas; }
From source file:Main.java
public static Cursor buildCursorByTrimming(Toolkit toolkit, Image image, int x, int y, String name, Cursor defaultCursor) {/*from w w w .j a v a 2s . c o m*/ Dimension d = toolkit.getBestCursorSize(image.getWidth(null), image.getHeight(null)); if (d == null || d.getWidth() <= 0 || d.getHeight() <= 0) return defaultCursor; BufferedImage out = new BufferedImage((int) d.getWidth(), (int) d.getHeight(), BufferedImage.TYPE_INT_ARGB); out.getGraphics().drawImage(image, 0, 0, null); return toolkit.createCustomCursor(out, new Point(x, y), name); }
From source file:Main.java
public static BufferedImage asCompatibleImage(Image img, int transparency) { BufferedImage ret = defaultScreenDeviceConfiguration().createCompatibleImage(img.getWidth(null), img.getHeight(null), transparency); Graphics2D gc = ret.createGraphics(); gc.setComposite(AlphaComposite.Src); gc.drawImage(img, 0, 0, null);//from ww w . j av a 2 s . co m gc.dispose(); return ret; }
From source file:com.taunova.app.libview.components.ImageHelpers.java
public static Dimension getScaledDimension(Image image, int width) { double k = ((double) image.getHeight(null)) / image.getWidth(null); int height = (int) (width * k); return new Dimension(width, height); }