Example usage for javax.swing ImageIcon getImageLoadStatus

List of usage examples for javax.swing ImageIcon getImageLoadStatus

Introduction

In this page you can find the example usage for javax.swing ImageIcon getImageLoadStatus.

Prototype

public int getImageLoadStatus() 

Source Link

Document

Returns the status of the image loading operation.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    ImageIcon icon = new ImageIcon("image.gif");
    icon.setDescription("Description of Image");

    System.out.println(icon.getImageLoadStatus());
}

From source file:net.chris54721.infinitycubed.utils.Utils.java

public static Image getImageResource(String imageName) {
    ImageIcon image = new ImageIcon(Toolkit.getDefaultToolkit().getImage(getResource(imageName, "png")));
    if (image.getImageLoadStatus() == MediaTracker.COMPLETE)
        return image.getImage();
    else {/* w  ww  .jav  a  2  s. c om*/
        LogHelper.error("Failed loading image resource " + imageName);
        return null;
    }
}

From source file:net.cbtltd.server.UploadFileService.java

private static boolean getImage(String fn, int fullsizepixels, int thumbnailpixels) {

    ImageIcon image = new ImageIcon(fn);
    //      if(image.getIconHeight() > 0 && image.getIconWidth() > 0) {
    if (image.getImageLoadStatus() == MediaTracker.COMPLETE) {
        ImageIcon fullsizeImage = new ImageIcon(
                image.getImage().getScaledInstance(-1, fullsizepixels, Image.SCALE_SMOOTH));
        LOG.debug("\n UploadFileService setImage image= " + image + " width=" + fullsizeImage.getIconWidth()
                + "  height=" + fullsizeImage.getIconHeight());
        BufferedImage fullsizeBufferedImage = new BufferedImage(fullsizeImage.getIconWidth(),
                fullsizeImage.getIconHeight(), BufferedImage.TYPE_INT_RGB);
        Graphics fullsizeGraphics = fullsizeBufferedImage.getGraphics();
        fullsizeGraphics.drawImage(fullsizeImage.getImage(), 0, 0, null);
        File fullsizeFile = new File(fn.substring(0, fn.lastIndexOf('.')) + ".jpg");
        fullsizeFile.delete();//from   w  w  w. ja v a  2  s .  c om

        try {
            ImageIO.write(fullsizeBufferedImage, FULLSIZE_JPEG, fullsizeFile);
        } catch (IOException x) {
            throw new RuntimeException("Error saving full sized image " + x.getMessage());
        }

        ImageIcon thumbnailImage = new ImageIcon(
                image.getImage().getScaledInstance(-1, thumbnailpixels, Image.SCALE_SMOOTH));
        File thumbnailFile = new File(fn.substring(0, fn.lastIndexOf('.')) + "Thumb.jpg");
        thumbnailFile.delete();
        BufferedImage thumbnailBufferedImage = new BufferedImage(thumbnailImage.getIconWidth(),
                thumbnailImage.getIconHeight(), BufferedImage.TYPE_INT_RGB);
        Graphics thumbnailGraphics = thumbnailBufferedImage.getGraphics();
        thumbnailGraphics.drawImage(thumbnailImage.getImage(), 0, 0, null);
        try {
            ImageIO.write(thumbnailBufferedImage, FULLSIZE_JPEG, thumbnailFile);
        } catch (IOException x) {
            throw new RuntimeException("Error saving thumbnail image " + x.getMessage());
        }
        return true;
    } else {
        LOG.error("\n UploadFileService setImage image= " + image + " width=" + image.getIconWidth()
                + "  height=" + image.getIconHeight());
        return false;
    }
}

From source file:net.cbtltd.server.UploadFileService.java

private static boolean getImage(String fn, BufferedImage image, Map<String, byte[]> images) {
    int fullsizepixels = Text.FULLSIZE_PIXELS_VALUE;
    int thumbnailpixels = Text.THUMBNAIL_PIXELS_VALUE;
    //      ByteBuffer byteArray = new ByteBuffer();
    ByteArrayOutputStream bOutputReg = new ByteArrayOutputStream();
    ByteArrayOutputStream bOutputThumb = new ByteArrayOutputStream();
    ImageIcon imageIcon = new ImageIcon(image);
    //      if(image.getIconHeight() > 0 && image.getIconWidth() > 0) {
    if (imageIcon.getImageLoadStatus() == MediaTracker.COMPLETE) {
        ImageIcon fullsizeImage = new ImageIcon(
                imageIcon.getImage().getScaledInstance(-1, fullsizepixels, Image.SCALE_SMOOTH));
        LOG.debug("\n UploadFileService setImage image= " + imageIcon + " width=" + fullsizeImage.getIconWidth()
                + "  height=" + fullsizeImage.getIconHeight());
        BufferedImage fullsizeBufferedImage = new BufferedImage(fullsizeImage.getIconWidth(),
                fullsizeImage.getIconHeight(), BufferedImage.TYPE_INT_RGB);
        Graphics fullsizeGraphics = fullsizeBufferedImage.getGraphics();
        fullsizeGraphics.drawImage(fullsizeImage.getImage(), 0, 0, null);
        String fullsizeFile = fn.substring(0, fn.lastIndexOf('.')) + ".jpg";

        try {/*from w  w  w  .  j a  v  a  2  s . c om*/
            ImageIO.write(fullsizeBufferedImage, FULLSIZE_JPEG, bOutputReg);
            bOutputReg.flush();
            images.put(fullsizeFile, bOutputReg.toByteArray());
            bOutputReg.close();
        } catch (IOException x) {
            throw new RuntimeException("Error saving full sized image " + x.getMessage());
        } catch (Exception e) {
            LOG.error(e.getMessage() + " Error saving full sized image: " + fullsizeFile);
        }

        ImageIcon thumbnailImage = new ImageIcon(
                imageIcon.getImage().getScaledInstance(-1, thumbnailpixels, Image.SCALE_SMOOTH));
        String thumbnailFile = fn.substring(0, fn.lastIndexOf('.')) + "Thumb.jpg";

        BufferedImage thumbnailBufferedImage = new BufferedImage(thumbnailImage.getIconWidth(),
                thumbnailImage.getIconHeight(), BufferedImage.TYPE_INT_RGB);
        Graphics thumbnailGraphics = thumbnailBufferedImage.getGraphics();
        thumbnailGraphics.drawImage(thumbnailImage.getImage(), 0, 0, null);
        try {
            ImageIO.write(thumbnailBufferedImage, FULLSIZE_JPEG, bOutputThumb);
            bOutputThumb.flush();
            images.put(thumbnailFile, bOutputThumb.toByteArray());
            bOutputThumb.close();
        } catch (IOException x) {
            throw new RuntimeException("Error saving thumbnail image " + x.getMessage());
        } catch (Exception e) {
            LOG.error(e.getMessage() + " Error saving thumbnail image: " + thumbnailFile);
        }

        return true;
    } else {
        LOG.error("\n UploadFileService setImage image= " + imageIcon + " width=" + imageIcon.getIconWidth()
                + "  height=" + imageIcon.getIconHeight());
        return false;
    }
}

From source file:net.cbtltd.server.UploadFileService.java

private static boolean getCompressedImage(String fn, BufferedImage image, Map<String, byte[]> images) {
    int fullsizepixels = Text.FULLSIZE_PIXELS_VALUE;
    int thumbnailpixels = Text.THUMBNAIL_PIXELS_VALUE;
    //      ByteBuffer byteArray = new ByteBuffer();
    ByteArrayOutputStream bOutputReg = new ByteArrayOutputStream();
    ByteArrayOutputStream bOutputThumb = new ByteArrayOutputStream();
    ImageIcon imageIcon = new ImageIcon(image);
    try {//from   w  w w . j  a  v  a 2 s  .c om
        GZIPOutputStream zipStreamReg = new GZIPOutputStream(bOutputReg);
        GZIPOutputStream zipStreamThumb = new GZIPOutputStream(bOutputThumb);

        if (imageIcon.getImageLoadStatus() == MediaTracker.COMPLETE) {
            ImageIcon fullsizeImage = new ImageIcon(
                    imageIcon.getImage().getScaledInstance(-1, fullsizepixels, Image.SCALE_SMOOTH));
            LOG.debug("\n UploadFileService setImage image= " + imageIcon + " width="
                    + fullsizeImage.getIconWidth() + "  height=" + fullsizeImage.getIconHeight());
            BufferedImage fullsizeBufferedImage = new BufferedImage(fullsizeImage.getIconWidth(),
                    fullsizeImage.getIconHeight(), BufferedImage.TYPE_INT_RGB);
            Graphics fullsizeGraphics = fullsizeBufferedImage.getGraphics();
            fullsizeGraphics.drawImage(fullsizeImage.getImage(), 0, 0, null);
            String fullsizeFile = fn.substring(0, fn.lastIndexOf('.')) + ".jpg";

            try {
                ImageIO.write(fullsizeBufferedImage, FULLSIZE_JPEG, zipStreamReg);
                zipStreamReg.close();
                bOutputReg.close();
                images.put(fullsizeFile, bOutputReg.toByteArray());
            } catch (IOException x) {
                throw new RuntimeException("Error saving full sized image " + x.getMessage());
            }

            ImageIcon thumbnailImage = new ImageIcon(
                    imageIcon.getImage().getScaledInstance(-1, thumbnailpixels, Image.SCALE_SMOOTH));
            String thumbnailFile = fn.substring(0, fn.lastIndexOf('.')) + "Thumb.jpg";

            BufferedImage thumbnailBufferedImage = new BufferedImage(thumbnailImage.getIconWidth(),
                    thumbnailImage.getIconHeight(), BufferedImage.TYPE_INT_RGB);
            Graphics thumbnailGraphics = thumbnailBufferedImage.getGraphics();
            thumbnailGraphics.drawImage(thumbnailImage.getImage(), 0, 0, null);
            try {
                ImageIO.write(thumbnailBufferedImage, FULLSIZE_JPEG, zipStreamThumb);
                zipStreamThumb.close();
                bOutputThumb.close();
                images.put(thumbnailFile, bOutputThumb.toByteArray());
            } catch (IOException x) {
                throw new RuntimeException("Error saving thumbnail image " + x.getMessage());
            }

            return true;
        } else {
            LOG.error("\n UploadFileService setImage image= " + imageIcon + " width=" + imageIcon.getIconWidth()
                    + "  height=" + imageIcon.getIconHeight());
            return false;
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return true;
}

From source file:org.jajuk.base.Album.java

/**
 * Return a cover file matching criteria or null.
 * /*from  w  ww  .ja va2 s .co  m*/
 * @param dirs : list of directories to search in
 * @param onlyStandardCovers to we consider only standard covers ?
 * 
 * @return a cover file matching criteria or null
 */
private File findCoverFile(Set<Directory> dirs, boolean onlyStandardCovers) {
    JajukFileFilter filter = new JajukFileFilter(ImageFilter.getInstance());
    for (Directory dir : dirs) {
        File fDir = dir.getFio(); // store this dir
        java.io.File[] files = fDir.listFiles();// null if none file
        // found
        for (int i = 0; files != null && i < files.length; i++) {
            if (files[i].exists()
                    // check size to avoid out of memory errors
                    && files[i].length() < MAX_COVER_SIZE * 1024
                    // Is it an image ?
                    && filter.accept(files[i])) {
                // Filter standard view if required
                if (onlyStandardCovers && !UtilFeatures.isStandardCover(files[i])) {
                    continue;
                }
                // Test the image is not corrupted
                try {
                    ImageIcon ii = new ImageIcon(files[i].getAbsolutePath());
                    // Note that at this point, the image is fully loaded (done in the ImageIcon
                    // constructor)
                    if (ii.getImageLoadStatus() == MediaTracker.COMPLETE) {
                        return files[i];
                    } else {
                        Log.debug("Problem loading: " + files[i].getAbsolutePath());
                    }
                } catch (Exception e) {
                    Log.error(e);
                }
            }
        }
    }
    return null;
}

From source file:org.xulux.swing.util.SwingUtils.java

/**
 *
 * @param resource the resource of the image
 * @param object the object to get the classloader from
 * @return the imageIcon found or null if not found
 *///from ww  w .  j  a v a 2s.com
public static ImageIcon getIcon(String resource, Object object) {
    if (object == null) {
        return null;
    }
    ImageCache cache = null;
    if (object instanceof Widget) {
        Widget w = (Widget) object;
        if (w.getPart() != null) {
            cache = w.getPart().getImageCache();
        }
    }
    ImageIcon icon = null;
    if (cache != null) {
        icon = cache.getImageIcon(resource);
    }
    if (icon == null) {
        URL imageURL = object.getClass().getClassLoader().getResource(resource);
        if (imageLoader != null) {
            icon = imageLoader.getIcon(imageURL);
        } else {
            if (imageURL != null) {
                icon = new ImageIcon(imageURL);
                if (icon.getImageLoadStatus() == MediaTracker.ERRORED) {
                    icon = null;
                    if (log.isWarnEnabled()) {
                        log.warn("Image type " + resource + " not supported by swing "
                                + "we advice you to add jimi to your classpath or convert your "
                                + "image to an image type supported by swing");
                    }
                }
            } else {
                if (log.isWarnEnabled()) {
                    log.warn("Image " + resource + " cannot be found");
                }
            }
        }
        if (icon != null && cache != null) {
            cache.addImage(resource, icon);
        }
    }
    return icon;
}