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?
This is well documented in the ImageIO javadoc :
If no registered ImageReader claims to be able to read the resulting stream, null is returned.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.