[英]Height and width of BufferedImage is null from InputStream
我正在使用此方法顯示我的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();
}
}
而bimg.getWidth()
和bimg.getHeight()
向我展示NullPointerException
。
有什么辦法嗎?
這在ImageIO javadoc中有詳細記錄 :
如果沒有注冊的ImageReader聲稱能夠讀取結果流,則返回null。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.