on 07-16-2006 8:58 AM
Hi!,
I am trying to render an image in portal on the fly.I have the buffered Image object and on encoding as a data stream, unable to generate an image from buffered Image object(garbage is getting displayed). Following is the code.
-
import java.awt.image.BufferedImage;
import com.sapportals.portal.prt.component.*;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
public class ImageRendererAbstract extends AbstractPortalComponent
{
public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)
{
BufferedImage s_Image = (BufferedImage) request.getComponentSession().getHttpSession().getAttribute("sessImage");
response.write("Image Buffer"+s_Image.toString());
request.getServletResponse(true).setContentType("image/jpeg");
try
{
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(request.getServletResponse(true).getOutputStream());
encoder.encode(s_Image);
request.getServletResponse(true).flushBuffer();
} catch (Exception e) {
// TODO: handle exception
}
}
}
-
Your input's would be really appreciated.
Thank you in advance.
Regards,
Vikram
Vikram,
1. Try to save generated image as file on server. Is it (image file) correctly displayed by any image viewer program?
2. I'm not sure about this two lines:
response.write("Image Buffer"+s_Image.toString());
request.getServletResponse(true).setContentType("image/jpeg");
Actually, I do not know what is relation between Portal and Servlet response. But try to remove first response.write -- it is necessary to set content type and all other headers before writing content. Also if "Image Buffer"+s_Image.toString() goes to output you probably get broken image. So just try to remove this statement.
VS
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
82 | |
10 | |
10 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.