Example usage for javax.swing ImageIcon getImage

List of usage examples for javax.swing ImageIcon getImage

Introduction

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

Prototype

@Transient
public Image getImage() 

Source Link

Document

Returns this icon's Image.

Usage

From source file:org.qsos.radar.GenerateRadar.java

/**
 * This class creates a composite in which the radar char will be
 * implemented//from   w  w w  . j  a v a2s .  c o  m
 * 
 * @param parent
 *             Composite where the chart will be seen
 * @param Categories
 *             String[] that contains the name of the elements [4 min and 7 max] the user has chosen to visualize
 * @param Scores
 *             Double[] that contains the average score of each category
 * @return Control
 * 
 */
public static Control createChart(Composite parent, String[] Categories, double[] Scores) {

    Composite Charcomposite = new Composite(parent, SWT.EMBEDDED);
    Charcomposite.setLayout(new FillLayout());
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    //
    for (int i = 0; i < CatNumber; i++) {
        dataset.addValue(Scores[i], getTitle(), Categories[i]);
    }

    String BackGroundMire = null;

    //Configuration of the spiderwebplot
    SpiderWebPlot plot = new SpiderWebPlot();
    plot.setDataset(dataset);
    plot.setMaxValue(JQConst.RADAR_MAX_VALUE);
    plot.setSeriesPaint(JQConst.RADAR_SERIES_PAINT);
    plot.setAxisLabelGap(JQConst.RADAR_AXIS_LABEL_GAP);
    plot.setHeadPercent(JQConst.RADAR_HEAD_PERCENT);
    plot.setInteriorGap(JQConst.RADAR_INTERIOR_GAP);
    plot.setWebFilled(true);

    //The backgroundpicture used as a spiderweb is chosen according to the 
    //number of categories selected
    switch (CatNumber) {
    case 4:
        BackGroundMire = JQConst.RADAR_SPIDERWEB_4;
        break;
    case 5:
        BackGroundMire = JQConst.RADAR_SPIDERWEB_5;
        break;
    case 6:
        BackGroundMire = JQConst.RADAR_SPIDERWEB_6;
        break;
    case 7:
        BackGroundMire = JQConst.RADAR_SPIDERWEB_7;
        break;
    }
    javax.swing.ImageIcon icon = new javax.swing.ImageIcon(BackGroundMire);
    plot.setBackgroundImage(icon.getImage());

    //chart creation
    JFreeChart chart = new JFreeChart(plot);

    //Here the background color from the shell is taken in order to match AWT and SWT backgrounds
    Color backgroundColor = parent.getBackground();

    //JFreechart doesn't support SWT so we create an AWT Frame that will depend on Charcomposite
    java.awt.Frame chartPanel = SWT_AWT.new_Frame(Charcomposite);
    chartPanel.setLayout(new java.awt.GridLayout());
    ChartPanel jfreeChartPanel = new ChartPanel(chart);

    chartPanel.setBackground(new java.awt.Color(backgroundColor.getRed(), backgroundColor.getGreen(),
            backgroundColor.getBlue()));

    chartPanel.add(jfreeChartPanel);
    chartPanel.pack();

    return parent;

}

From source file:ImageUtil.java

/**
 * get image thumbnail/* w  w w.j a va  2 s  .  c o m*/
 * @param imageFile
 */
public static ImageIcon getImageThumbnail(File imageFile, int width, int height) {
    ImageIcon thumbnail = null;
    if (imageFile != null && imageFile.isFile()) {
        ImageIcon tmpIcon = new ImageIcon(imageFile.getPath());
        if (tmpIcon != null) {
            if (tmpIcon.getIconWidth() > width) {
                int targetHeight = width / tmpIcon.getIconWidth() * tmpIcon.getIconHeight();
                if (targetHeight > height) {
                    targetHeight = height;
                } else {
                    targetHeight = -1;
                }
                thumbnail = new ImageIcon(
                        tmpIcon.getImage().getScaledInstance(width, targetHeight, Image.SCALE_AREA_AVERAGING));
            } else {
                thumbnail = tmpIcon;
            }
        }
    }
    return thumbnail;
}

From source file:com.reydentx.core.common.PhotoUtils.java

public static byte[] waterMarkJPG(String baseImagePath, String waterMartPath) {
    try {/*from  w  w  w  . ja  v a  2  s  .com*/
        File origFile = new File(baseImagePath);
        ImageIcon icon = new ImageIcon(origFile.getPath());
        BufferedImage bufferedImage = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(),
                BufferedImage.TYPE_INT_RGB);
        Graphics graphics = bufferedImage.getGraphics();
        graphics.drawImage(icon.getImage(), 0, 0, null);

        ImageIcon png = new ImageIcon(waterMartPath);
        graphics.drawImage(png.getImage(), 0, 0, null);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageIO.write(bufferedImage, "jpg", baos);
        baos.flush();
        byte[] imageInByte = baos.toByteArray();

        return imageInByte;
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:edu.ku.brc.ui.GraphicsUtils.java

/**
 * Gets a scaled icon and if it doesn't exist it creates one and scales it
 * @param icon image to be scaled//w w w.j a v  a2  s  .co m
 * @param iconSize the icon size (Std)
 * @param scaledIconSize the new scaled size in pixels
 * @return the scaled icon
 */
public static BufferedImage getBufferedImage(final ImageIcon icon) {
    Image imgMemory = icon.getImage();

    //make sure all pixels in the image were loaded
    imgMemory = new ImageIcon(imgMemory).getImage();

    int w = icon.getIconWidth();
    int h = icon.getIconHeight();
    BufferedImage bufferedImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

    Graphics2D graphics2D = bufferedImage.createGraphics();
    graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    graphics2D.drawImage(imgMemory, 0, 0, w, h, 0, 0, w, h, null);
    graphics2D.dispose();

    return bufferedImage;
}

From source file:com.piaoyou.util.ImageUtil.java

public static Image getScaledInstance(Image srcImage, int width, int height) {
    boolean useSun = false;
    ImageFilter filter;//from  www  .  j  a v a  2 s  .  c o m
    if (useSun) {
        //log.trace("use sun scalefilter");
        filter = new java.awt.image.AreaAveragingScaleFilter(width, height);
    } else {
        //log.trace("use nguoimau scalefilter");
        filter = new AreaAveragingScaleFilter(width, height);
        //           filter = new java.awt.image.AreaAveragingScaleFilter(width, height);
    }
    ImageProducer prod = new FilteredImageSource(srcImage.getSource(), filter);
    Image newImage = Toolkit.getDefaultToolkit().createImage(prod);
    ImageIcon imageIcon = new ImageIcon(newImage);
    return imageIcon.getImage();
}

From source file:edu.ku.brc.ui.IconManager.java

/**
 * Creates a Black and White image from the color
 * @param img the image to be converted/*from  w w  w . j a  va 2  s.  c o m*/
 * @return new B&W image
 */
public static ImageIcon createFadedImage(final ImageIcon icon) {
    Image image = GrayFilter.createDisabledImage(icon.getImage());
    return new ImageIcon(image);

    /*BufferedImage bi = new BufferedImage(img.getIconWidth(), img.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics g = bi.createGraphics();
    g.drawImage(img.getImage(), 0, 0, null);
    g.setColor(new Color(255, 255, 255, 128));
    g.fillRect(0, 0, bi.getWidth(), bi.getHeight());
    ImageIcon icon = new ImageIcon(bi);
    g.dispose();
    return icon;*/
}

From source file:edu.ku.brc.ui.IconManager.java

/**
 * Creates a Black and White image from the color
 * @param img the image to be converted//from   w ww . j a va2 s. c o m
 * @return new B&W image
 */
public static ImageIcon createBWImage(final ImageIcon img) {
    BufferedImage bi = new BufferedImage(img.getIconWidth(), img.getIconHeight(), BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.createGraphics();
    g.drawImage(img.getImage(), 0, 0, null);
    ColorConvertOp colorConvert = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
    colorConvert.filter(bi, bi);
    ImageIcon icon = new ImageIcon(bi);
    g.dispose();
    return icon;
}

From source file:br.com.diegosilva.jsfcomponents.util.Utils.java

public static byte[] resizeImage(byte[] imageData, String contentType, int width) {
    ImageIcon icon = new ImageIcon(imageData);

    double ratio = (double) width / icon.getIconWidth();
    int resizedHeight = (int) (icon.getIconHeight() * ratio);

    int imageType = "image/png".equals(contentType) ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
    BufferedImage bImg = new BufferedImage(width, resizedHeight, imageType);
    Graphics2D g2d = bImg.createGraphics();
    g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g2d.drawImage(icon.getImage(), 0, 0, width, resizedHeight, null);
    g2d.dispose();/* w ww  .  ja  v a  2s  . c om*/

    String formatName = "";
    if ("image/png".equals(contentType))
        formatName = "png";
    else if ("image/jpeg".equals(contentType) || "image/jpg".equals(contentType))
        formatName = "jpeg";

    ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
    try {
        ImageIO.write(bImg, formatName, baos);
        return baos.toByteArray();
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:edu.ku.brc.specify.BackupAndRestoreApp.java

/**
 * //from   ww  w. j  a v  a2 s  . c o m
 */
public static void startApp() {
    // Then set this
    IconManager.setApplicationClass(BackupAndRestoreApp.class);
    IconManager.loadIcons(XMLHelper.getConfigDir("icons_datamodel.xml")); //$NON-NLS-1$
    IconManager.loadIcons(XMLHelper.getConfigDir("icons_plugins.xml")); //$NON-NLS-1$
    IconManager.loadIcons(XMLHelper.getConfigDir("icons_disciplines.xml")); //$NON-NLS-1$

    try {
        UIHelper.OSTYPE osType = UIHelper.getOSType();
        if (osType == UIHelper.OSTYPE.Windows) {
            UIManager.setLookAndFeel(new PlasticLookAndFeel());
            PlasticLookAndFeel.setPlasticTheme(new ExperienceBlue());

        } else if (osType == UIHelper.OSTYPE.Linux) {
            UIManager.setLookAndFeel(new PlasticLookAndFeel());
        }
    } catch (Exception e) {
        UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(BackupAndRestoreApp.class, e);
        log.error("Can't change L&F: ", e); //$NON-NLS-1$
    }

    ImageIcon helpIcon = IconManager.getIcon("AppIcon", IconSize.Std16); //$NON-NLS-1$
    HelpMgr.initializeHelp("SpecifyHelp", helpIcon.getImage()); //$NON-NLS-1$

    // Startup Specify
    BackupAndRestoreApp backupAndRestoreApp = new BackupAndRestoreApp();

    RolloverCommand.setHoverImg(IconManager.getIcon("DropIndicator")); //$NON-NLS-1$

    // THis type of start up ALWAYS assumes the .Specify directory is in there "home" directory.
    backupAndRestoreApp.preStartUp();
    backupAndRestoreApp.startUp();
}

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

private static byte[] getImageBlob(String fn, int fullsizepixels) {
    try {/* www. ja  v a 2s .c o m*/
        ImageIcon image = new ImageIcon(fn);

        ImageIcon logoImage = new ImageIcon(
                image.getImage().getScaledInstance(fullsizepixels, -1, Image.SCALE_SMOOTH));
        BufferedImage bufferedImage = new BufferedImage(logoImage.getIconWidth(), logoImage.getIconHeight(),
                BufferedImage.TYPE_INT_RGB);
        Graphics graphics = bufferedImage.getGraphics();
        graphics.drawImage(logoImage.getImage(), 0, 0, null);
        fn = fn.substring(0, fn.lastIndexOf('.')) + ".Blob.jpg";
        File file = new File(fn);
        file.delete();
        ImageIO.write(bufferedImage, FULLSIZE_JPEG, file);

        InputStream is = new FileInputStream(file);
        long length = file.length();
        if (length > Integer.MAX_VALUE) {
            throw new IOException("File is too large for logo - maximum size = " + Integer.MAX_VALUE);
        }
        byte[] bytes = new byte[(int) length];
        int offset = 0;
        int numRead = 0;
        while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
            offset += numRead;
        }
        if (offset < bytes.length) {
            throw new IOException("Could not completely read file " + file.getName());
        }
        is.close();

        return bytes;
    } catch (IOException x) {
        throw new RuntimeException("Error creating BLOB image " + x.getMessage());
    }
}