简体   繁体   English

无法使用ImageIO从控制器写入tif文件

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

I have the jai-imageio jar and have added it to my class path. 我有jai-imageio jar并将它添加到我的类路径中。 I just don't know to write a .tif image to the response's output stream. 我只是不知道将.tif图像写入响应的输出流。 Can someone help me? 有人能帮我吗?

Here is my code: 这是我的代码:

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

I know that javax.imageio.ImageIO doesn't support tif images, so what do I do with jai-imageio to make it worK? 我知道javax.imageio.ImageIO不支持tif图像,那么我怎么处理jai-imageio才能让它成为烦恼? I'm lost. 我迷路了。

Note: the code above works fine for other image types like jpeg and png. 注意:上面的代码适用于其他图像类型,如jpeg和png。

It look like that you're going in the wrong direction as to storing and serving uploaded images. 看起来你正朝着存储和提供上传图像的错误方向前进。 You don't need the whole Java 2D API for that at all. 您根本不需要整个Java 2D API。

When you retrieve an uploaded image, just do 当您检索上传的图像时,就这样做

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

When you serve an uploaded image, just do 当您提供上传的图片时,就这样做

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

You don't need to massage/manipulate the bytes at all. 您根本不需要按摩/操纵字节。 Just stream them unmodified. 只是简单地流动它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM