Search in sources :

Example 6 with MediaTracker

use of java.awt.MediaTracker in project Aspose.BarCode-for-Java by aspose-barcode.

the class MyBarCode method paint.

public void paint(Graphics g) {
    // The path to the resource directory.
    String dataDir = Utils.getDataDir(MyBarCode.class) + "BarcodeImage/RenderingFeatures/";
    String fileName = dataDir + "barcode.png";
    BarCodeBuilder bb = new BarCodeBuilder();
    bb.setEncodeType(com.aspose.barcode.EncodeTypes.CODE_128);
    bb.setCodeText("12345678");
    bb.save(fileName);
    // Load and Draw the image on applet
    MediaTracker tr = new MediaTracker(this);
    File sourceimage = new File(fileName);
    Image image;
    try {
        image = ImageIO.read(sourceimage);
        tr.addImage(image, 0);
        g.drawImage(image, 0, 0, this);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : MediaTracker(java.awt.MediaTracker) BarCodeBuilder(com.aspose.barcode.BarCodeBuilder) IOException(java.io.IOException) Image(java.awt.Image) File(java.io.File)

Example 7 with MediaTracker

use of java.awt.MediaTracker in project bioformats by openmicroscopy.

the class AWTImageTools method loadImage.

/**
 * Ensures the given AWT image is fully loaded.
 */
public static boolean loadImage(Image image) {
    if (image instanceof BufferedImage)
        return true;
    MediaTracker tracker = new MediaTracker(OBS);
    tracker.addImage(image, 0);
    try {
        tracker.waitForID(0);
    } catch (InterruptedException exc) {
        return false;
    }
    if (MediaTracker.COMPLETE != tracker.statusID(0, false))
        return false;
    return true;
}
Also used : MediaTracker(java.awt.MediaTracker) BufferedImage(java.awt.image.BufferedImage)

Example 8 with MediaTracker

use of java.awt.MediaTracker in project ma-core-public by infiniteautomation.

the class ViewGraphicLoader method loadDirectory.

private void loadDirectory(File dir, String baseId) throws Exception {
    String id = baseId + dir.getName();
    String name = id;
    String typeStr = "imageSet";
    int width = -1;
    int height = -1;
    int textX = 5;
    int textY = 5;
    File[] files = dir.listFiles();
    Arrays.sort(files);
    List<String> imageFiles = new ArrayList<String>();
    for (File file : files) {
        if (file.getName().startsWith(".")) {
        // ignore '.' files and directories
        } else if (file.isDirectory())
            loadDirectory(file, id + ".");
        else if (IGNORE_THUMBS.equalsIgnoreCase(file.getName())) {
        // no op
        } else if (INFO_FILE_NAME.equalsIgnoreCase(file.getName())) {
            // Info file
            Properties props = new Properties();
            props.load(new FileInputStream(file));
            name = getProperty(props, "name", name);
            typeStr = getProperty(props, "type", "imageSet");
            width = getIntProperty(props, "width", width);
            height = getIntProperty(props, "height", height);
            textX = getIntProperty(props, "text.x", textX);
            textY = getIntProperty(props, "text.y", textY);
        } else {
            // Image file. Subtract the load path from the image path
            String imagePath = file.getPath().substring(path.length());
            // Replace Windows-style '\' path separators with '/'
            imagePath = imagePath.replaceAll("\\\\", "/");
            imageFiles.add(imagePath);
        }
    }
    if (!imageFiles.isEmpty()) {
        if (width == -1 || height == -1) {
            String imagePath = path + imageFiles.get(0);
            Image image = Toolkit.getDefaultToolkit().getImage(imagePath);
            MediaTracker tracker = new MediaTracker(new Container());
            tracker.addImage(image, 0);
            tracker.waitForID(0);
            if (width == -1)
                width = image.getWidth(null);
            if (height == -1)
                height = image.getHeight(null);
            if (width == -1 || height == -1)
                throw new Exception("Unable to derive image dimensions from " + imagePath);
        }
        String[] imageFileArr = imageFiles.toArray(new String[imageFiles.size()]);
        ViewGraphic g;
        if ("imageSet".equals(typeStr))
            g = new ImageSet(id, name, imageFileArr, width, height, textX, textY);
        else if ("dynamic".equals(typeStr))
            g = new DynamicImage(id, name, imageFileArr[0], width, height, textX, textY);
        else
            throw new Exception("Invalid type: " + typeStr);
        viewGraphics.add(g);
    }
}
Also used : MediaTracker(java.awt.MediaTracker) ArrayList(java.util.ArrayList) Properties(java.util.Properties) Image(java.awt.Image) FileInputStream(java.io.FileInputStream) Container(java.awt.Container) File(java.io.File)

Example 9 with MediaTracker

use of java.awt.MediaTracker in project lwjgl by LWJGL.

the class AppletLoader method getImage.

/**
 * Get Image from path provided
 *
 * @param url location of the image
 * @return the Image file
 */
public Image getImage(URL url) {
    try {
        MediaTracker tracker = new MediaTracker(this);
        Image image = super.getImage(url);
        // wait for image to load
        tracker.addImage(image, 0);
        tracker.waitForAll();
        // if no errors return image
        if (!tracker.isErrorAny()) {
            return image;
        }
    } catch (Exception e) {
    /* */
    }
    return null;
}
Also used : MediaTracker(java.awt.MediaTracker) Image(java.awt.Image) AccessControlException(java.security.AccessControlException) IOException(java.io.IOException)

Example 10 with MediaTracker

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

the class Image method waitForImage.

public static java.awt.Image waitForImage(java.awt.Image image) {
    MediaTracker mediaTracker = new MediaTracker(new Container());
    mediaTracker.addImage(image, 0);
    try {
        mediaTracker.waitForID(0);
        if (image.getWidth(null) == -1 || image.getHeight(null) == -1)
            image = null;
    } catch (InterruptedException e) {
        image = null;
    }
    return image;
}
Also used : MediaTracker(java.awt.MediaTracker) Container(java.awt.Container)

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