簡體   English   中英

InputStream中BufferedImage的高度和寬度為null

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM