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:edu.ku.brc.ui.GraphicsUtils.java

/**
 * @param name// w  ww. j a  v  a  2  s .c  o m
 * @param imgIcon
 * @return
 */
public static String uuencodeImage(final String name, final ImageIcon imgIcon) {
    try {
        BufferedImage tmp = new BufferedImage(imgIcon.getIconWidth(), imgIcon.getIconWidth(),
                BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = tmp.createGraphics();
        //g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        g2.drawImage(imgIcon.getImage(), 0, 0, imgIcon.getIconWidth(), imgIcon.getIconWidth(), null);
        g2.dispose();

        ByteArrayOutputStream output = new ByteArrayOutputStream(8192);
        ImageIO.write(tmp, "PNG", output);
        byte[] outputBytes = output.toByteArray();
        output.close();

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        UUEncoder uuencode = new UUEncoder(name);
        uuencode.encode(new ByteArrayInputStream(outputBytes), bos);
        return bos.toString();

    } catch (Exception ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(GraphicsUtils.class, ex);
        ex.printStackTrace();
    }
    return "";
}

From source file:Main.java

public void setImage(ImageIcon icon) {
    image = icon.getImage().getScaledInstance(this.getWidth(), this.getHeight(), Image.SCALE_DEFAULT);
    repaint();/*from www  .  ja  v a 2s . co  m*/
}

From source file:Crop.java

public Crop() {
    super();/*  www  .  ja  v a  2  s  .c  om*/
    ImageIcon icon = new ImageIcon("java2s.PNG");
    image = icon.getImage();
    image = createImage(new FilteredImageSource(image.getSource(), new CropImageFilter(73, 63, 141, 131)));
}

From source file:ConvolveIt.java

public Image getImage(String imageFile) {
    ImageIcon icon = new ImageIcon(imageFile);
    return icon.getImage();
}

From source file:Scale.java

public Scale() {
    super();
    ImageIcon icon = new ImageIcon("java2s.GIF");
    image = icon.getImage();
}

From source file:Main.java

@Override
public void mouseClicked(MouseEvent e) {
    ImageIcon img = new ImageIcon("yourImage.png");
    //place image in your working directory
    addImage(img.getImage());
}

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 . j a v  a 2 s.  co m

        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:Main.java

public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel p = new JPanel();
    ImageIcon icon = new ImageIcon("r.gif");

    JButton b1 = new JButton("Regular", icon);
    p.add(b1);//from   w ww .  j  a  v a 2s  .  c o  m

    Image image = GrayFilter.createDisabledImage(icon.getImage());
    JButton b2 = new JButton("GrayFilter", new ImageIcon(image));
    p.add(b2);

    getContentPane().add(p);

    pack();
    setVisible(true);
}

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 o  m*/
            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:ImageTest.java

public ImageLabel(ImageIcon icon) {
    setIcon(icon);//from  ww w.  j  ava  2  s  .  c o m
    // setMargin(new Insets(0,0,0,0));
    setIconTextGap(0);
    // setBorderPainted(false);
    setBorder(null);
    setText(null);
    setSize(icon.getImage().getWidth(null), icon.getImage().getHeight(null));
}