• Post Reply Bookmark Topic Watch Topic
  • New Topic

Image Manipulation in JSP without saving to disk  RSS feed

 
J Wright
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to...

upload an image...

save the original (B&W) image stream in a javabean..

display a manipulated image (white turned into transparent, black changed to another color)

and save the original to disk once a selection has been made

I will post more details on how I've started going about this later...

Any suggestions..
 
J Wright
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I have...

an upload file that sends image data to place.jsp

place.jsp stores the image data to a java bean (in the form of a MemoryCacheImageInputStream with set and get methods) and displays image.jsp

image.jsp retrieves the MemoryCacheImageInputStream and creates a BufferedImage from it, then creates a filter, takes the BufferedImage and filter and creates an ImageProducer from it

The ImageProducer is then converted back to a BufferedImage and written to the output stream

here is most of thumb.jsp...


response.setContentType("image/jpeg");
OutputStream osResponse = response.getOutputStream();

// Retrieves jpg inputstream from the bean set in place.jsp
MemoryCacheImageInputStream isJpgOld = myBean.getMCIIS();
if(isJpgOld != null)
{
isJpgOld.reset();
BufferedImage biOriginal = ImageIO.read(isJpgOld);
ImageFilter filter = new myRGBImageFilter();

ImageProducer ip = new FilteredImageSource(biOriginal.getSource(), filter);

BufferedImage biNew = toBufferedImage(Toolkit.getDefaultToolkit().createImage(ip));
try{
ImageIO.write(biNew,"jpg",osResponse);
}
catch (IOException e)
{

}

}

This seems to work but I have a few problems...

the major problem is ...

I need to be able to access the original image again after the user chooses the manipulation they like...
Right now I'm calling myBean.getMCIIS().mark() right after I set the MCIIS (MemoryCacheImageInputStream)
but it doesn't work because I have created a file called thumb3.jsp with the same code as thumb.jsp and had place.jsp
display that as well but only one of the manipulated images shows up..
so using mark() and reset() are not doing what I need them to do
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!