Saturday, January 05, 2013

Java Tip of the Day: Converting an InputStream to a BufferedImage

I was looking for a standard way using the JDK to convert an InputStream into a BufferedImage as part of a JUnit test. The solution was quite simple using ImageIO.

Code

1
2
3
4
5
6
7
public BufferedImage convertInputStreamToBufferedImage(final InputStream is) throws IOException {
    BufferedImage image = null;
    if (is != null) {
        image = ImageIO.read(is);
    }
    return image;
}

0 comments :

Popular Posts