Yagami Light
Yagami Light

Reputation: 1796

Height and width of BufferedImage is null from InputStream

I am using this method to show my BufferedImage:

public void setUriFromInpustream(InputStream in) {  
    BufferedImage bimg;
    try {
        bimg = ImageIO.read(in);
        originAspectRatio = (double) bimg.getWidth() / (double) bimg.getHeight();
        if (width == 0)
            width = bimg.getWidth();
        if (height == 0)
            height = bimg.getHeight();
        setPreserveOriginAspectRatio(preserveOriginAspectRatio);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

And the bimg.getWidth() and bimg.getHeight() is showing me NullPointerException.

Any solution?

Upvotes: 0

Views: 364

Answers (1)

Viktor K.
Viktor K.

Reputation: 2740

This is well documented in the ImageIO javadoc:

If no registered ImageReader claims to be able to read the resulting stream, null is returned.

Upvotes: 1

Related Questions