| Author |
need help to generate png image from svg file
|
lily zou
Ranch Hand
Joined: Jan 15, 2002
Posts: 50
|
|
Hi, there It would be much appreciated if any one could help me out. I have a servlet where I use PNGTranscoder to generate png image and display it. This is my code: PNGTranscoder trans = new PNGTranscoder(); File svgFile = new File(SVGFILE); long svgSize = svgFile.length(); TranscoderInput input = new TranscoderInput(svgURI); ByteArrayOutputStream outStream = new ByteArrayOutputStream((int)svgSize); TranscoderOutput output = new TranscoderOutput(outStream); trans.transcode(input,output); HOWEVER, the page above codes rendered is blank. May I ask why the png file is not created corrected ? Tons of thanks, Lily
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
not 100% sure, but it might be this part of the line with the int in () ByteArrayOutputStream((int)svgSize); Eric
|
 |
lily zou
Ranch Hand
Joined: Jan 15, 2002
Posts: 50
|
|
That syntax is correct. I think the reason might be that I used ByteArrayOutputStream as PNGTranscoder's output stream and ByteArrayOutputStream will not out put its contents to browser. However, PNGTranscoder can only accept ByteArrayOutputStream as it output stream. I am wondering if there is any way that I can get around this problem.
|
 |
Andy Bowes
Ranch Hand
Joined: Jan 14, 2003
Posts: 171
|
|
In order to pass back the contents of the ByteArrayOutputStream as part of the HttpResponse you will need to do something like this at the end of your code: response.setContentType("image/png"); ServletOutputStream servletOutput = response.getOutputStream(); servletOutput.write(outStream.toByteArray()); servletOutput.flush(); response.setStatus(HTTPServletResponse.SC_OK); Hope this is what you are after. [ April 10, 2003: Message edited by: Andy Bowes ]
|
Andy Bowes<br />SCJP, SCWCD<br />I like deadlines, I love the whoosing noise they make as they go flying past - Douglas Adams
|
 |
lily zou
Ranch Hand
Joined: Jan 15, 2002
Posts: 50
|
|
Thanks a lot, Andy. Yes, this is what I need. I need to set contenttype to be image/png. Thanks again, Lily
|
 |
 |
|
|
subject: need help to generate png image from svg file
|
|
|