Example usage for javax.imageio ImageIO read

List of usage examples for javax.imageio ImageIO read

Introduction

In this page you can find the example usage for javax.imageio ImageIO read.

Prototype

public static BufferedImage read(ImageInputStream stream) throws IOException 

Source Link

Document

Returns a BufferedImage as the result of decoding a supplied ImageInputStream with an ImageReader chosen automatically from among those currently registered.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    // Read from a URL
    URL url = new URL("http://java.org/source.gif");
    Image image = ImageIO.read(url);

    JFrame frame = new JFrame();
    JLabel label = new JLabel(new ImageIcon(image));
    frame.getContentPane().add(label, BorderLayout.CENTER);
    frame.pack();//from   w  w w .jav a 2  s  . co m
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL url = new URL("http://www.java2s.com/style/download.png");
    final Image img = ImageIO.read(url);

    Runnable r = new Runnable() {

        @Override/*w ww. j  a v  a  2s .c  om*/
        public void run() {
            JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(img)));
        }
    };
    SwingUtilities.invokeLater(r);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JOptionPane jop = new JOptionPane("Message", JOptionPane.QUESTION_MESSAGE, JOptionPane.DEFAULT_OPTION);

    JDialog dialog = jop.createDialog("Dialog Title");

    Image image = ImageIO.read(new URL("http://www.java2s.com/style/download.png"));
    dialog.setIconImage(image);/*from   ww  w  .j  ava2  s  .  c om*/
    dialog.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL url = new URL("http://www.java2s.com/style/download.png");
    BufferedImage origImg = ImageIO.read(url);

    JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(origImg)));

    File newFile = new File("new.png");
    ImageIO.write(origImg, "png", newFile);
    BufferedImage newImg = ImageIO.read(newFile);

    JOptionPane.showMessageDialog(null, new JLabel("New", new ImageIcon(newImg), SwingConstants.LEFT));
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    byte[] picture = new byte[2048]; // your image data

    InputStream in = new ByteArrayInputStream(picture);

    BufferedImage buf = ImageIO.read(in);
    ColorModel model = buf.getColorModel();
    int height = buf.getHeight();
    int width = buf.getWidth();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL url = new URL("http://www.java2s.com/style/download.png");
    final BufferedImage bi = ImageIO.read(url);
    final String size = bi.getWidth() + "x" + bi.getHeight();
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            JLabel l = new JLabel(size, new ImageIcon(bi), SwingConstants.RIGHT);
            JOptionPane.showMessageDialog(null, l);
        }//from w  w  w  .  j  a  v  a 2  s. com
    });
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL url = new URL("http://www.java2s.com/style/download.png");
    BufferedImage image = ImageIO.read(url);

    int w = image.getWidth();
    int h = image.getHeight();
    Ellipse2D.Double ellipse1 = new Ellipse2D.Double(10, 10, 20, 30);
    Ellipse2D.Double ellipse2 = new Ellipse2D.Double(15, 15, 20, 30);
    Area circle = new Area(ellipse1);
    circle.subtract(new Area(ellipse2));

    BufferedImage result = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = result.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
    g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g.setClip(circle);/*ww w  .  j ava2  s .c o  m*/
    g.drawImage(image, 0, 0, null);
    g.dispose();

    ImageIO.write(result, "png", new File("result.png"));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    File sourceimage = new File("source.gif");
    Image image = ImageIO.read(sourceimage);

    JFrame frame = new JFrame();
    JLabel label = new JLabel(new ImageIcon(image));
    frame.getContentPane().add(label, BorderLayout.CENTER);
    frame.pack();/*w  w  w .j  a  v  a2  s.co m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL url16 = new URL("http://www.java2s.com/style/download.png");
    URL url32 = new URL("http://www.java2s.com/style/download.png");

    final List<Image> icons = new ArrayList<Image>();
    icons.add(ImageIO.read(url16));
    icons.add(ImageIO.read(url32));

    JFrame f = new JFrame();
    f.setIconImages(icons);//  w  w w. j a  va  2s .  com
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    f.setSize(200, 100);
    f.setVisible(true);
}

From source file:SaveIt.java

public static void main(String args[]) throws IOException {
    // Read//from  w  w w .j a  va 2  s .  co  m
    File inputFile = new File("java2s.jpg");
    BufferedImage input = ImageIO.read(inputFile);
    // Convert
    Kernel kernel = new Kernel(3, 3, SHARP);
    ConvolveOp convolveOp = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
    int width = input.getWidth();
    int height = input.getHeight();
    BufferedImage output = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    convolveOp.filter(input, output);
    // Save
    File outputFile = new File("java2s.png");
    ImageIO.write(output, "PNG", outputFile);
}