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:BasicDraw.java

public static void main(String[] args) {
    Image image = new ImageIcon("image.gif").getImage();

    width = image.getWidth(null);/*from w  w w . j a va 2 s  . c  om*/
    height = image.getHeight(null);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Image image = new ImageIcon("image.gif").getImage();

    BufferedImage bimage = new BufferedImage(image.getWidth(null), image.getHeight(null),
            BufferedImage.TYPE_INT_RGB);

    Graphics2D g = bimage.createGraphics();
    g.drawImage(image, 0, 0, null);//from  w w  w .j av a2  s .c  o m
    g.dispose();
}

From source file:BasicDraw.java

public static void main(String[] args) {
    Image image = Toolkit.getDefaultToolkit().getImage("image.gif");
    int width = image.getWidth(null);
    int height = image.getHeight(null);

    if (width >= 0) {
        // The image has been fully loaded
    } else {//from  www  .  ja v  a2 s  .  c  o m
        // The image has not been fully loaded
    }

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Image img = new ImageIcon("test.png").getImage();

    BufferedImage bufferedImage = new BufferedImage(img.getWidth(null), img.getHeight(null),
            BufferedImage.TYPE_INT_RGB);

    Graphics g = bufferedImage.createGraphics();
    g.drawImage(img, 0, 0, null);/*from w  ww  .jav  a 2 s.  c  om*/
    g.dispose();

    ImageIO.write(bufferedImage, "png", new File("a.png"));
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    robot.keyPress(KeyEvent.VK_PRINTSCREEN);
    robot.delay(40);//from ww  w .  j av a  2 s .  com
    robot.keyRelease(KeyEvent.VK_PRINTSCREEN);
    robot.delay(404);

    Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
    DataFlavor[] flavors = cb.getAvailableDataFlavors();
    for (DataFlavor flavor : flavors) {
        if (flavor.toString().indexOf("java.awt.Image") <= 0) {
            continue;
        }
        Image i = (Image) cb.getData(flavor);
        BufferedImage bi = new BufferedImage(i.getWidth(null), i.getHeight(null), BufferedImage.TYPE_INT_RGB);
        Graphics2D g = bi.createGraphics();
        g.drawImage(i, 0, 0, null);
        g.dispose();
        ImageIO.write(bi, "png", new File("c:/Java_Dev/test.png"));
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL urlImage1 = new URL("http://www.java2s.com/style/download.png");

    final Image fgImage = ImageIO.read(urlImage1);
    int w = fgImage.getWidth(null);
    int h = fgImage.getHeight(null);
    final BufferedImage bgImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);

    final BufferedImage finalImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = finalImage.createGraphics();
    g.drawImage(bgImage, 0, 0, null);/*ww  w.  jav  a2  s  . c o  m*/
    g.drawImage(fgImage, 0, 0, null);
    g.dispose();

    Runnable r = new Runnable() {
        @Override
        public void run() {
            JPanel gui = new JPanel(new GridLayout(1, 0, 5, 5));

            gui.add(new JLabel(new ImageIcon(bgImage)));
            gui.add(new JLabel(new ImageIcon(fgImage)));
            gui.add(new JLabel(new ImageIcon(finalImage)));

            JOptionPane.showMessageDialog(null, gui);
        }
    };
    SwingUtilities.invokeLater(r);
}

From source file:Main.java

public static void main(String[] args) throws IOException {

    final int SCALE = 2;

    Image img = new ImageIcon(new URL("http://www.java2s.com/style/download.png")).getImage();

    BufferedImage bi = new BufferedImage(SCALE * img.getWidth(null), SCALE * img.getHeight(null),
            BufferedImage.TYPE_INT_ARGB);

    Graphics2D grph = (Graphics2D) bi.getGraphics();
    grph.scale(SCALE, SCALE);//ww  w . jav  a2  s .  c  om

    grph.drawImage(img, 0, 0, null);
    grph.dispose();

    ImageIO.write(bi, "png", new File("double_size.png"));
}

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 resizeToHeight(Image image, int h) {
    int w = image.getWidth(null) * h / image.getHeight(null);
    Image newimg = image.getScaledInstance(w, h, Image.SCALE_SMOOTH); // scale it the smooth way  
    return newimg;
}

From source file:Util.java

/**
 * Converts an Image to a BufferedImage/*from  w  w w .  ja va2  s . c om*/
 */
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;
}