Search in sources :

Example 16 with MediaTracker

use of java.awt.MediaTracker in project jdk8u_jdk by JetBrains.

the class MultiResolutionDisabledImageTest method testMRDisabledImage.

private static void testMRDisabledImage(Image image) throws Exception {
    Image disabledImage = GrayFilter.createDisabledImage(image);
    MediaTracker mediaTracker = new MediaTracker(new JLabel());
    mediaTracker.addImage(disabledImage, 0);
    mediaTracker.waitForID(0);
    BufferedImage buffImage = new BufferedImage(IMAGE_SIZE, IMAGE_SIZE, BufferedImage.TYPE_INT_RGB);
    int x = IMAGE_SIZE / 2;
    int y = IMAGE_SIZE / 2;
    Graphics2D g = buffImage.createGraphics();
    g.scale(1, 1);
    g.drawImage(disabledImage, 0, 0, null);
    int rgb1x = buffImage.getRGB(x, y);
    g.scale(2, 2);
    g.drawImage(disabledImage, 0, 0, null);
    int rgb2x = buffImage.getRGB(x, y);
    g.dispose();
    if (rgb1x == rgb2x) {
        throw new RuntimeException("Disabled image is the same for the base" + "image and the resolution variant");
    }
}
Also used : MediaTracker(java.awt.MediaTracker) JLabel(javax.swing.JLabel) MultiResolutionImage(java.awt.image.MultiResolutionImage) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) BaseMultiResolutionImage(java.awt.image.BaseMultiResolutionImage) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 17 with MediaTracker

use of java.awt.MediaTracker in project JMRI by JMRI.

the class SplashWindow method splashWindowDisplay.

public void splashWindowDisplay(JPanel splashMsg) {
    //super("JMRI");
    this.setUndecorated(true);
    // get the splash image
    MediaTracker mt = new MediaTracker(this);
    splashIm = Toolkit.getDefaultToolkit().getImage(FileUtil.findURL("resources/logo.gif", FileUtil.Location.INSTALLED));
    mt.addImage(splashIm, 0);
    try {
        mt.waitForID(0);
    } catch (InterruptedException ie) {
        // retain if needed later
        Thread.currentThread().interrupt();
    }
    JLabel l = new JLabel(new ImageIcon(splashIm, "JMRI splash screen"));
    l.setOpaque(true);
    if (splashMsg != null) {
        JPanel full = new JPanel();
        full.setLayout(new BoxLayout(full, BoxLayout.Y_AXIS));
        l.setAlignmentX(CENTER_ALIGNMENT);
        splashMsg.setAlignmentX(CENTER_ALIGNMENT);
        full.add(l);
        full.add(splashMsg);
        getContentPane().add(full);
    } else {
        getContentPane().add(l);
    }
    pack();
    /* Center the window and pad the frame size slightly to put some space 
         * between logo and frame border*/
    Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
    Rectangle winDim = getBounds();
    winDim.height = winDim.height + 10;
    winDim.width = winDim.width + 10;
    setLocation((screenDim.width - winDim.width) / 2, (screenDim.height - winDim.height) / 2);
    setSize(winDim.width, winDim.height);
    // and show
    setVisible(true);
}
Also used : ImageIcon(javax.swing.ImageIcon) JPanel(javax.swing.JPanel) MediaTracker(java.awt.MediaTracker) BoxLayout(javax.swing.BoxLayout) Rectangle(java.awt.Rectangle) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension)

Example 18 with MediaTracker

use of java.awt.MediaTracker in project JMRI by JMRI.

the class NamedIcon method createRotatedImage.

/**
     * The following was based on a text-rotating applet from David Risner,
     * available at http://www.risner.org/java/rotate_text.html
     *
     * @param pImage     Image to transform
     * @param pComponent Component containing the image, needed to obtain a
     *                   MediaTracker to process the image consistently with
     *                   display
     * @param pRotation  0-3 number of 90-degree rotations needed
     * @return new Image object containing the rotated input image
     */
public Image createRotatedImage(Image pImage, Component pComponent, int pRotation) {
    if (log.isDebugEnabled()) {
        log.debug("createRotatedImage: pRotation= " + pRotation + ", mRotation= " + mRotation);
    }
    if (pRotation == 0) {
        return pImage;
    }
    MediaTracker mt = new MediaTracker(pComponent);
    mt.addImage(pImage, 0);
    try {
        mt.waitForAll();
    } catch (InterruptedException ie) {
        // retain if needed later
        Thread.currentThread().interrupt();
    }
    int w = pImage.getWidth(null);
    int h = pImage.getHeight(null);
    int[] pixels = new int[w * h];
    PixelGrabber pg = new PixelGrabber(pImage, 0, 0, w, h, pixels, 0, w);
    try {
        pg.grabPixels();
    } catch (InterruptedException ie) {
    }
    int[] newPixels = new int[w * h];
    // transform the pixels
    MemoryImageSource imageSource = null;
    switch(pRotation) {
        case // 90 degrees
        1:
            for (int y = 0; y < h; ++y) {
                for (int x = 0; x < w; ++x) {
                    newPixels[x * h + y] = pixels[y * w + (w - 1 - x)];
                }
            }
            imageSource = new MemoryImageSource(h, w, ColorModel.getRGBdefault(), newPixels, 0, h);
            break;
        case // 180 degrees
        2:
            for (int y = 0; y < h; ++y) {
                for (int x = 0; x < w; ++x) {
                    newPixels[x * h + y] = pixels[(w - 1 - x) * h + (h - 1 - y)];
                }
            }
            imageSource = new MemoryImageSource(w, h, ColorModel.getRGBdefault(), newPixels, 0, w);
            break;
        case // 270 degrees
        3:
            for (int y = 0; y < h; ++y) {
                for (int x = 0; x < w; ++x) {
                    newPixels[x * h + y] = pixels[(h - 1 - y) * w + x];
                }
            }
            imageSource = new MemoryImageSource(h, w, ColorModel.getRGBdefault(), newPixels, 0, h);
            break;
        default:
            log.warn("Unhandled rotation code: {}", pRotation);
            break;
    }
    Image myImage = pComponent.createImage(imageSource);
    mt.addImage(myImage, 1);
    try {
        mt.waitForAll();
    } catch (InterruptedException ie) {
    }
    return myImage;
}
Also used : MediaTracker(java.awt.MediaTracker) PixelGrabber(java.awt.image.PixelGrabber) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) MemoryImageSource(java.awt.image.MemoryImageSource)

Example 19 with MediaTracker

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

the class ImageReader method loadImage.

public SimpleImage loadImage(String pFilename) throws Exception {
    File file = new File(pFilename);
    if (!file.exists())
        throw new FileNotFoundException(pFilename);
    Image fileImg = Toolkit.getDefaultToolkit().createImage(pFilename);
    MediaTracker tracker = new MediaTracker(owner);
    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) FileNotFoundException(java.io.FileNotFoundException) SimpleHDRImage(org.jwildfire.image.SimpleHDRImage) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) SimpleImage(org.jwildfire.image.SimpleImage) File(java.io.File) BufferedImage(java.awt.image.BufferedImage)

Example 20 with MediaTracker

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

the class Launcher method getImage.

private SimpleImage getImage(String pName) throws Exception {
    byte[] imgData = getImagedata(pName);
    Image fileImg = Toolkit.getDefaultToolkit().createImage(imgData);
    MediaTracker tracker = new MediaTracker(frame);
    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) SimpleImage(org.jwildfire.image.SimpleImage) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) 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