Example usage for java.awt MediaTracker addImage

List of usage examples for java.awt MediaTracker addImage

Introduction

In this page you can find the example usage for java.awt MediaTracker addImage.

Prototype

public void addImage(Image image, int id) 

Source Link

Document

Adds an image to the list of images being tracked by this media tracker.

Usage

From source file:FilterLab.java

public void init() {
    originalImage = getImage(getDocumentBase(), "e.gif");
    MediaTracker tracker = new MediaTracker(this);
    tracker.addImage(originalImage, 0);
    try {/* w w w.j  ava2 s  .c  om*/
        tracker.waitForAll();
    } catch (Exception e) {
    }
    filteredImage = originalImage;
    btn.addActionListener(this);
    add(btn);
}

From source file:Main.java

ContentPanel() {
    MediaTracker mt = new MediaTracker(this);
    bgimage = Toolkit.getDefaultToolkit().getImage("a.jpg");
    mt.addImage(bgimage, 0);
    try {//from  w  ww.  j a v  a  2s  .c  o m
        mt.waitForAll();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:AttributesApp.java

public void loadImage() {
    image = Toolkit.getDefaultToolkit().getImage("largeJava2sLogo.gif");
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(image, 1);
    try {//from  w ww  .  j a v  a2  s  . c o m
        mt.waitForAll();
    } catch (Exception e) {
        System.out.println("Exception while loading.");
    }

    if (image.getWidth(this) == -1) {
        System.out.println("no images");
        System.exit(0);
    }
}

From source file:ImageView.java

public void loadImage() {

    URL url = getClass().getResource(fileName);
    im = Toolkit.getDefaultToolkit().getImage(url);

    // ----- This part omitted from course notes for brevity -----
    // Use a MediaTracker to show the "best"? way of waiting
    // for an image to load, and how to check for errors.
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(im, 0);
    try {//from ww w  .  j a  v  a 2 s  . com
        mt.waitForID(0);
    } catch (InterruptedException e) {
        System.err.println("Unexpected interrupt in waitForID!");
        return;
    }
    if (mt.isErrorID(0)) {
        System.err.println("Couldn't load image file " + fileName);
        return;
    }

    // Now that we know the image has been loaded,
    // it is safe to take its width and height.
    // ----- End of part omitted from course notes for brevity -----
    width = im.getWidth(this);
    height = im.getHeight(this);
    setSize(width, height);
}

From source file:FilterLab.java

public void init() {
    originalImage = getImage(getDocumentBase(), "emily.gif");
    MediaTracker tracker = new MediaTracker(this);
    tracker.addImage(originalImage, 0);
    try {//from  w  w  w .  java  2 s .c  o m
        tracker.waitForAll();
    } catch (Exception e) {
    }
    filteredImage = originalImage;
    btn.addActionListener(this);
    add(btn);
}

From source file:RasterDemo.java

RasterPanel() {
    setBackground(Color.white);/* ww  w .  ja v  a  2 s . c  om*/
    setSize(450, 400);

    Image image = getToolkit().getImage("largeJava2sLogo.jpg");

    MediaTracker mt = new MediaTracker(this);
    mt.addImage(image, 1);
    try {
        mt.waitForAll();
    } catch (Exception e) {
        System.out.println("Exception while loading image.");
    }

    if (image.getWidth(this) == -1) {
        System.out.println("No jpg file");
        System.exit(0);
    }

    bi1 = new BufferedImage(image.getWidth(this), image.getHeight(this), BufferedImage.TYPE_INT_ARGB);
    Graphics2D big = bi1.createGraphics();
    big.drawImage(image, 0, 0, this);
    bi = bi1;
}

From source file:MainClass.java

public void init() {
    MediaTracker mt = new MediaTracker(this);
    i = getImage(getDocumentBase(), "rosey.jpg");
    mt.addImage(i, 0);
    try {//from ww w .  ja va2s  .  c  o m
        mt.waitForAll();
        int width = i.getWidth(this);
        int height = i.getHeight(this);
        j = createImage(new FilteredImageSource(i.getSource(),
                new CropImageFilter(width / 3, height / 3, width / 3, height / 3)));
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:ColorConvertDemo.java

public void loadImage() {
    displayImage = Toolkit.getDefaultToolkit().getImage("largeJava2sLogo.jpg");
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(displayImage, 1);
    try {//from  w  w  w  .j a v a2s .co m
        mt.waitForAll();
    } catch (Exception e) {
        System.out.println("Exception while loading.");
    }
    if (displayImage.getWidth(this) == -1) {
        System.out.println("No jpg ");
        System.exit(0);
    }
}

From source file:RotateImage45Degrees.java

public RotateImage45Degrees(String imageFile) {
    addNotify();/*from   w  ww  .ja  va2  s.com*/
    frameInsets = getInsets();
    inputImage = Toolkit.getDefaultToolkit().getImage(imageFile);

    MediaTracker mt = new MediaTracker(this);
    mt.addImage(inputImage, 0);
    try {
        mt.waitForID(0);
    } catch (InterruptedException ie) {
    }

    sourceBI = new BufferedImage(inputImage.getWidth(null), inputImage.getHeight(null),
            BufferedImage.TYPE_INT_ARGB);

    Graphics2D g = (Graphics2D) sourceBI.getGraphics();
    g.drawImage(inputImage, 0, 0, null);

    AffineTransform at = new AffineTransform();

    // scale image
    at.scale(2.0, 2.0);

    // rotate 45 degrees around image center
    at.rotate(45.0 * Math.PI / 180.0, sourceBI.getWidth() / 2.0, sourceBI.getHeight() / 2.0);

    /*
     * translate to make sure the rotation doesn't cut off any image data
     */
    AffineTransform translationTransform;
    translationTransform = findTranslation(at, sourceBI);
    at.preConcatenate(translationTransform);

    // instantiate and apply affine transformation filter
    BufferedImageOp bio;
    bio = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);

    destinationBI = bio.filter(sourceBI, null);

    int frameInsetsHorizontal = frameInsets.right + frameInsets.left;
    int frameInsetsVertical = frameInsets.top + frameInsets.bottom;
    setSize(destinationBI.getWidth() + frameInsetsHorizontal, destinationBI.getHeight() + frameInsetsVertical);
    show();
}

From source file:ImageFrame.java

/**
 * Set the image from a file./*from w  w w .  j  av a  2s  .c o m*/
 */
public void setImage(File file) throws IOException {
    // load the image
    Image image = getToolkit().getImage(file.getAbsolutePath());

    // wait for the image to entirely load
    MediaTracker tracker = new MediaTracker(this);
    tracker.addImage(image, 0);
    try {
        tracker.waitForID(0);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    if (tracker.statusID(0, true) != MediaTracker.COMPLETE) {
        throw new IOException("Could not load: " + file + " " + tracker.statusID(0, true));
    }

    setTitle(file.getName());
    setImage(image);
}