Pregunta

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.

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top