Search in sources :

Example 1 with MediaTracker

use of java.awt.MediaTracker in project JWildfire by thargor6.

the class WelcomeInternalFrame method getImage.

private SimpleImage getImage(String pName) throws Exception {
    byte[] imgData = getImagedata(pName);
    Image fileImg = Toolkit.getDefaultToolkit().createImage(imgData);
    MediaTracker tracker = new MediaTracker(this);
    tracker.addImage(fileImg, 0);
    tracker.waitForID(0);
    int width = fileImg.getWidth(null);
    int height = fileImg.getHeight(null);
    BufferedImage bImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics g = bImg.getGraphics();
    g.drawImage(fileImg, 0, 0, null);
    fileImg = null;
    return new SimpleImage(bImg, width, height);
}
Also used : Graphics(java.awt.Graphics) MediaTracker(java.awt.MediaTracker) SimpleImage(org.jwildfire.image.SimpleImage) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) SimpleImage(org.jwildfire.image.SimpleImage) BufferedImage(java.awt.image.BufferedImage)

Example 2 with MediaTracker

use of java.awt.MediaTracker in project JSettlers2 by jdmonin.

the class SOCFaceButton method loadImages.

private static synchronized void loadImages(Component c) {
    if (images == null) {
        tracker = new MediaTracker(c);
        Toolkit tk = c.getToolkit();
        Class<?> clazz = c.getClass();
        images = new Image[NUM_FACES];
        robotImages = new Image[NUM_ROBOT_FACES];
        /**
         * load the images
         */
        robotImages[0] = tk.getImage(clazz.getResource(IMAGEDIR + "/robot.gif"));
        tracker.addImage(robotImages[0], 0);
        for (int i = 1; i < NUM_FACES; i++) {
            images[i] = tk.getImage(clazz.getResource(IMAGEDIR + "/face" + i + ".gif"));
            tracker.addImage(images[i], 0);
        }
        for (int i = 1; i < NUM_ROBOT_FACES; i++) {
            // Client possibly only has robot.gif.
            // Check getResource vs null, and use MediaTracker;
            // drawFace can check tracker.statusID vs MediaTracker.COMPLETE.
            URL imgSrc = clazz.getResource(IMAGEDIR + "/robot" + i + ".gif");
            if (imgSrc != null) {
                robotImages[i] = tk.getImage(imgSrc);
                tracker.addImage(robotImages[i], i);
            }
        }
        try {
            tracker.waitForID(0);
        } catch (InterruptedException e) {
        }
        if (tracker.isErrorID(0)) {
            System.out.println("Error loading Face images");
        }
    }
}
Also used : MediaTracker(java.awt.MediaTracker) Toolkit(java.awt.Toolkit) URL(java.net.URL)

Example 3 with MediaTracker

use of java.awt.MediaTracker in project Spark by igniterealtime.

the class GraphicUtils method load.

/**
 * Loading an image via a MediaTracker
 *
 * @param image
 * @throws InterruptedException
 * @throws IOException
 */
public static void load(Image image) throws InterruptedException, IOException {
    // any component
    MediaTracker tracker = new MediaTracker(new Label());
    // will do
    tracker.addImage(image, 0);
    tracker.waitForID(0);
    if (tracker.isErrorID(0))
        throw new IOException("error loading image");
}
Also used : MediaTracker(java.awt.MediaTracker) Label(java.awt.Label) JLabel(javax.swing.JLabel) IOException(java.io.IOException)

Example 4 with MediaTracker

use of java.awt.MediaTracker in project triplea by triplea-game.

the class GameRunner method getGameIcon.

public static Image getGameIcon(final Window frame) {
    Image img = null;
    try {
        img = frame.getToolkit().getImage(GameRunner.class.getResource("ta_icon.png"));
    } catch (final Exception ex) {
        ClientLogger.logError("ta_icon.png not loaded", ex);
    }
    final MediaTracker tracker = new MediaTracker(frame);
    tracker.addImage(img, 0);
    try {
        tracker.waitForAll();
    } catch (final InterruptedException ex) {
        Thread.currentThread().interrupt();
    }
    return img;
}
Also used : MediaTracker(java.awt.MediaTracker) Image(java.awt.Image)

Example 5 with MediaTracker

use of java.awt.MediaTracker in project triplea by triplea-game.

the class ReliefImageBreaker method loadImage.

/**
 * Asks the user to select an image and then it loads it up into an Image
 * object and returns it to the calling class.
 *
 * @return The loaded image.
 */
private Image loadImage() {
    ToolLogger.info("Select the map");
    final String mapName = new FileOpen("Select The Map", mapFolderLocation, ".gif", ".png").getPathString();
    if (mapName != null) {
        final Image img = Toolkit.getDefaultToolkit().createImage(mapName);
        final MediaTracker tracker = new MediaTracker(new Panel());
        tracker.addImage(img, 1);
        try {
            tracker.waitForAll();
            return img;
        } catch (final InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }
    return null;
}
Also used : Panel(java.awt.Panel) MediaTracker(java.awt.MediaTracker) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage)

Aggregations

MediaTracker (java.awt.MediaTracker)30 Image (java.awt.Image)17 BufferedImage (java.awt.image.BufferedImage)16 Graphics (java.awt.Graphics)7 IOException (java.io.IOException)7 Toolkit (java.awt.Toolkit)5 Container (java.awt.Container)4 JLabel (javax.swing.JLabel)4 Component (java.awt.Component)3 MultiResolutionImage (java.awt.image.MultiResolutionImage)3 File (java.io.File)3 URL (java.net.URL)3 JPanel (javax.swing.JPanel)3 SimpleImage (org.jwildfire.image.SimpleImage)3 Dimension (java.awt.Dimension)2 Graphics2D (java.awt.Graphics2D)2 Panel (java.awt.Panel)2 PixelGrabber (java.awt.image.PixelGrabber)2 BarCodeBuilder (com.aspose.barcode.BarCodeBuilder)1 Frame (java.awt.Frame)1