[英]Image is null after creation with not null InputStream
我有以下代碼:
public BufferedImage inputStreamToImage (InputStream stream) {
BufferedImage image = null;
if (stream != null ) {
try {
image = ImageIO.read(stream);
// image is still null here <--
} catch (IOException ex) {
System.out.println(ex.getMessage());
}
}
return image;
}
我測試InputStream是否為null,而不是。 然后我從InputStream創建一個新的BufferedImage。 再沒有什么問題,代碼執行就像它正在工作。 但是當我嘗試使用圖像時它是空的。換句話說,在“成功”創建之后,我測試圖像並且它為空。
編輯
我通過html表單上傳.tif文件,如下所示:
<form action="webresources/read" method="post" enctype="multipart/form-data">
<p>
Select a file : <input type="file" name="file" id="file" />
</p>
<input type="submit" value="Upload It" />
</form>
有幫助嗎? 提前致謝 :)
啊! 所以..原因是ImageIO.read()不支持.tif圖像。 我嘗試用.jpg,它工作正常。
是否有可能在ImageIO的文檔中聲明以下情況 - “InputStream包含在ImageInputStream中。如果沒有注冊的ImageReader聲稱能夠讀取結果流,則返回null。”?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.