문제

I have the jai-imageio jar and have added it to my class path. I just don't know to write a .tif image to the response's output stream. 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? I'm lost.

Note: the code above works fine for other image types like jpeg and 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.

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 ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top