List of usage examples for java.awt Image getWidth
public abstract int getWidth(ImageObserver observer);
From source file:org.springframework.ws.samples.mtom.service.StubImageRepository.java
@Override public void storeImage(String name, Image image) throws IOException { logger.info("Storing image " + name + " [" + image.getWidth(null) + "x" + image.getHeight(null) + "]"); images.put(name, image);/*from w ww. j a v a 2s . co m*/ }
From source file:GrayImage.java
public void paint(Graphics g) { Image myImage = new ImageIcon("yourImage.png").getImage(); BufferedImage bufferedImage = new BufferedImage(myImage.getHeight(this), myImage.getWidth(this), BufferedImage.TYPE_BYTE_GRAY); Graphics gi = bufferedImage.getGraphics(); gi.drawImage(myImage, 0, 0, null);//ww w. j a va 2 s. c om gi.dispose(); Graphics2D g2d = (Graphics2D) g; g2d.drawImage(bufferedImage, null, 0, 0); }
From source file:ImageBorderHack.java
public BufferedImage createBufferedImage(Image img) { BufferedImage buff = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics gfx = buff.createGraphics(); gfx.drawImage(img, 0, 0, null);//from w w w . ja va 2s .c o m gfx.dispose(); return buff; }
From source file:IconLine.java
public void addImage(Image image) { vImages.add(image); iWidth = iWidth + image.getWidth(null); iHeight = image.getHeight(null); }
From source file:edu.clemson.cs.nestbed.client.gui.MotePanel.java
public void setIcon(Image icon) { this.icon = icon; Dimension size = new Dimension((int) (1.88 * icon.getWidth(null)), (int) (1.88 * icon.getHeight(null))); setSize(size);// w ww .j a va 2s .c o m setPreferredSize(size); setMinimumSize(size); setMaximumSize(size); }
From source file:Main.java
public static BufferedImage toBufferedImage(Image image) { if (image instanceof BufferedImage) { return (BufferedImage) image; }// www .jav a 2s. c om // This code ensures that all the pixels in the image are loaded image = new ImageIcon(image).getImage(); // Determine if the image has transparent pixels; for this method's // implementation, see Determining If an Image Has Transparent Pixels boolean hasAlpha = true; // Create a buffered image with a format that's compatible with the screen BufferedImage bimage = null; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); try { // Determine the type of transparency of the new buffered image int transparency = Transparency.OPAQUE; if (hasAlpha) { transparency = Transparency.BITMASK; } // Create the buffered image GraphicsDevice gs = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gs.getDefaultConfiguration(); bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency); } catch (HeadlessException e) { // The system does not have a screen } if (bimage == null) { // Create a buffered image using the default color model int type = BufferedImage.TYPE_INT_RGB; if (hasAlpha) { type = BufferedImage.TYPE_INT_ARGB; } bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type); } // Copy image to buffered image Graphics g = bimage.createGraphics(); // Paint the image onto the buffered image g.drawImage(image, 0, 0, null); g.dispose(); return bimage; }
From source file:IconLine.java
public void paintIcon(Component c, Graphics g, int x, int y) { int dx = 0;//from w w w.j a v a2s .c o m for (int i = 0; i < vImages.size(); i++) { Image image = (Image) vImages.get(i); g.drawImage(image, x + dx, y, c); dx += image.getWidth(c) + iSpace; } }
From source file:org.lnicholls.galleon.util.Tools.java
public static Image getResourceAsImage(Class theClass, String resource) { try {/*w w w .j a v a 2 s.c o m*/ if (!resource.startsWith("/")) resource = "/" + resource; InputStream is = theClass.getResourceAsStream(resource); BufferedInputStream bis = new BufferedInputStream(is); if (is != null) { byte[] byBuf = new byte[is.available()]; int byteRead = bis.read(byBuf, 0, is.available()); Image img = Toolkit.getDefaultToolkit().createImage(byBuf); if (img != null) { img.getWidth(null); is.close(); return img; } is.close(); } } catch (Exception ex) { Tools.logException(Tools.class, ex, "Could not load resource: " + resource); } return null; }
From source file:Main.java
License:asdf
public Dimension getPreferredSize(JComponent c) { FontMetrics metrics = c.getFontMetrics(c.getFont()); String tipText = ((JToolTip) c).getTipText(); if (tipText == null) { tipText = ""; }/* w ww . j av a2 s. c om*/ Image image = new ImageIcon("yourImage").getImage(); int width = SwingUtilities.computeStringWidth(metrics, tipText); int height = metrics.getHeight() + image.getHeight(c); if (width < image.getWidth(c)) { width = image.getWidth(c); } return new Dimension(width, height); }
From source file:ImageBorderHack.java
public void fillTexture(Graphics2D g2, Image img, int x, int y, int w, int h) { BufferedImage buff = createBufferedImage(img); Rectangle anchor = new Rectangle(x, y, img.getWidth(null), img.getHeight(null)); TexturePaint paint = new TexturePaint(buff, anchor); g2.setPaint(paint);// w ww . j a va2s.c om g2.fillRect(x, y, w, h); }