|
Hi, I was looking for way to improve my code where I stream an SVG Document
(created using Batik DOM) to a browser. So basically I need to get from SVG
Document to a byte[] which can be passed via Servlet which sets the Mime type,
and so displayed. Currently I use my method below, but as part of this method I am creating
a file object and retrieving my byte[] from that. Ideally (it may actually
become a requirement) I’d like to avoid this step and be able to retrieve
a byte[] without creating a file object. Thanks in advance for any help, Regards, Dylan public static void
streamSVGIntoImageFormat(HttpSession session, Document doc, String mimeType) { try { ImageTranscoder
t = null; if
(mimeType.equals(Config.JPEG)) {
t = new JPEGTranscoder();
t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(.8)); }
else if (mimeType.equals(Config.PNG)) { t
= new PNGTranscoder(); }
else if (mimeType.equals(Config.TIFF)) {
t = new TIFFTranscoder(); }
else {
System.out.println("ERROR: A request to stream an image was recieved with
an unsupported mime type: " + mimeType);
return; }
TranscoderInput input = new TranscoderInput(doc);
OutputStream ostream = new FileOutputStream("c:\\out." + mimeType);
TranscoderOutput output = new TranscoderOutput(ostream);
t.transcode(input, output);
ostream.flush();
ostream.close();
byte[] bytes = getBytesFromFile(new File("c:\\out." + mimeType));
session.setAttribute("jpegbytes", bytes);
session.setAttribute("mimeType", mimeType); } catch (Exception e) {
e.printStackTrace();
System.out.println("Error in streaming SVG because " +
e.getMessage()); } } |
- scaling the document itself, not the image on display kloassie
- Re: scaling the document itself, not the image on d... Tonny Kohar
- Streaming SVG Document without creating temporary f... Dylan Browne
- RE: Streaming SVG Document without creating tem... Javid Alimohideen
- Re: Streaming SVG Document without creating tem... thomas . deweese
- RE: Streaming SVG Document without creating... Dylan Browne
- How to rotate a complete SVG ? Maik Schürer
- Re: How to rotate a complete SVG ? André Ávila
- RE: How to rotate a complete SVG ? sugawara
