cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Image not rendering

0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

0 Kudos

Valery,

Thanks for your reply.

1) Yes, I have tried storing as a file and can view the image. Albiet would like to display the image directly on the page as the image generated is dynamic each time the application is run.

2) Removed all the write statements but still no luck!!.

Regards.

Answers (0)