Example usage for java.awt Image getHeight

List of usage examples for java.awt Image getHeight

Introduction

In this page you can find the example usage for java.awt Image getHeight.

Prototype

public abstract int getHeight(ImageObserver observer);

Source Link

Document

Determines the height of the image.

Usage

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);/*  w w w . ja v a  2s. com*/
}

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 ww  .j a va  2s .co  m
    gfx.dispose();
    return buff;
}

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 = "";
    }/*www.ja  v  a 2s  .co m*/
    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:IconLine.java

public void addImage(Image image) {
    vImages.add(image);

    iWidth = iWidth + image.getWidth(null);
    iHeight = image.getHeight(null);
}

From source file:Main.java

public static BufferedImage toBufferedImage(Image image) {
    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }/* w  w  w  . j a  v a2s.co m*/

    // 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: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);// www . j av a2 s.c  o m
    setPreferredSize(size);
    setMinimumSize(size);
    setMaximumSize(size);
}

From source file:org.echocat.velma.Resources.java

@Nonnull
public Image getIcon(@Nonnegative int size) {
    Image result = null;/*ww w . ja v  a2  s.  c om*/
    for (Image icon : _icons) {
        if (icon.getHeight(null) == size) {
            result = icon;
            break;
        }
    }
    if (result == null) {
        throw new IllegalArgumentException("Could not find an image for size " + size + "x" + size + ".");
    }
    return result;
}

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);//from  w ww . ja v a  2s . c o m
    g2.fillRect(x, y, w, h);
}

From source file:Main.java

/**
 * This method returns a buffered image with the contents of an image
 * This snippet was taken from: http://www.exampledepot.com/egs/java.awt.image/Image2Buf.html
 * @param image// w  w w  . ja  v  a  2s  . c o m
 * @return The buffered image
 */
public static BufferedImage toBufferedImage(Image image) {
    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }

    // 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 e661 Determining If an Image Has Transparent Pixels
    boolean hasAlpha = hasAlpha(image);

    // 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:net.rptools.lib.image.ThumbnailManager.java

private Image createThumbnail(File file) throws IOException {
    // Gather info
    File thumbnailFile = getThumbnailFile(file);
    if (thumbnailFile.exists()) {
        return ImageUtil.getImage(thumbnailFile);
    }//from  www  .  j  ava  2 s  . c om

    Image image = ImageUtil.getImage(file);
    Dimension imgSize = new Dimension(image.getWidth(null), image.getHeight(null));

    // Test if we Should we bother making a thumbnail ?
    // Jamz: New size 100k (was 30k) and put in check so we're not creating thumbnails LARGER than the original...
    if (file.length() < 102400
            || (imgSize.width <= thumbnailSize.width && imgSize.height <= thumbnailSize.height)) {
        return image;
    }
    // Transform the image
    SwingUtil.constrainTo(imgSize, Math.min(image.getWidth(null), thumbnailSize.width),
            Math.min(image.getHeight(null), thumbnailSize.height));
    BufferedImage thumbnailImage = new BufferedImage(imgSize.width, imgSize.height,
            ImageUtil.pickBestTransparency(image));

    Graphics2D g = thumbnailImage.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g.drawImage(image, 0, 0, imgSize.width, imgSize.height, null);
    g.dispose();

    // Use png to preserve transparency
    FileUtils.writeByteArrayToFile(thumbnailFile, ImageUtil.imageToBytes(thumbnailImage, "png"));

    return thumbnailImage;
}