簡體   English   中英

無法使用ImageIO從控制器寫入tif文件

[英]Unable to write tif file from controller using ImageIO

我有jai-imageio jar並將它添加到我的類路徑中。 我只是不知道將.tif圖像寫入響應的輸出流。 有人能幫我嗎?

這是我的代碼:

RenderedOp image = JAI.create("fileload", filepath);
ImageIO.write(image.getAsBufferdImage(), "tif", response.getOutputStream());

我知道javax.imageio.ImageIO不支持tif圖像,那么我怎么處理jai-imageio才能讓它成為煩惱? 我迷路了。

注意:上面的代碼適用於其他圖像類型,如jpeg和png。

看起來你正朝着存儲和提供上傳圖像的錯誤方向前進。 您根本不需要整個Java 2D API。

當您檢索上傳的圖像時,就這樣做

InputStream input = uploadedFile.getInputStream();
OutputStream output = new FileOutputStream(uniqueImagePath);
// Now write input to output in a loop the usual way.

當您提供上傳的圖片時,就這樣做

InputStream input = new FileInputStream(uniqueImagePath);
OutputStream output = response.getOutputStream();
// Now write input to output in a loop the usual way.

您根本不需要按摩/操縱字節。 只是簡單地流動它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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