tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Java > Image IO > How to load image from ImageInputStream

How to load image from ImageInputStream 

Java Image IO provides pluggable architecture for accessing images transparently. It is simple, flexible and allows us to plugin various image readers and writers with ease. The following example shows loading an image from ImageInputStream as swing label image icon.

stpatricks_08.gif

File Name  :  
com/bethecoder/tutorials/imageio/LoadImageFromImageInputStreamTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.imageio;

import java.awt.BorderLayout;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.imageio.ImageIO;
import javax.imageio.stream.ImageInputStream;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class LoadImageFromImageInputStreamTest {

  /**
   @param args
   @throws IOException 
   */
  public static void main(String[] argsthrows IOException {

    InputStream input = new FileInputStream("C:/Temp/stpatricks_08.gif");
    ImageInputStream imageInput = ImageIO.createImageInputStream(input);
    BufferedImage bufImage = ImageIO.read(imageInput);

    JFrame frame = new JFrame("Image loaded from ImageInputStream");
    JLabel label = new JLabel(new ImageIcon(bufImage));
    frame.getContentPane().add(label, BorderLayout.CENTER);
    frame.pack();
    frame.setVisible(true);
  }

}
   

It gives the following output,

img4miis.jpg


                    Print

   



Books Recommendation

 
 
bl  br