Java Image Width Get getWidth(java.awt.Image image)

Here you can find the source of getWidth(java.awt.Image image)

Description

get Width

License

Open Source License

Declaration

public static int getWidth(java.awt.Image image) throws InterruptedException 

Method Source Code

//package com.java2s;

public class Main {
    private static java.awt.MediaTracker s_mediaTracker = new java.awt.MediaTracker(new java.awt.Panel());
    private static java.awt.image.ImageObserver s_imageObserver = new java.awt.image.ImageObserver() {
        public boolean imageUpdate(java.awt.Image image, int infoflags, int x, int y, int width, int height) {
            return true;
        }/* w w w  .j a v a  2  s  .  c  o m*/
    };

    public static int getWidth(java.awt.Image image) throws InterruptedException {
        waitForImage(image);
        return image.getWidth(s_imageObserver);
    }

    private static void waitForImage(java.awt.Image image) throws InterruptedException {
        s_mediaTracker.addImage(image, 0);
        try {
            s_mediaTracker.waitForID(0);
        } finally {
            s_mediaTracker.removeImage(image);
        }
    }
}

Related

  1. getWidth(final Image image)
  2. getWidth(Image pImage)