Hi Tanel,
Tanel Suurhans wrote:
Im trying to load a SVG file into a Java Image object with Batik ImageTranscoder but i cant figure out a clean and good solution.
Neither have i found anything good poking around in google results.
So maybe anyone has a idea or even some working code how to do this.
At the moment im trying to load a SVG file using PNGTranscoder and then transcoding it to TranscoderOutput,
making it a byteArray and creating a image with it.
This is pretty ugly ;)
You might look at Cameron's Icon impl:
http://mcc.id.au/2005/04/SVGIcon.java
Also some people use the JSVGCanvas as a factory, you construct a canvas of the proper size and grab it's offscreen buffer.
I personally would probably subclass the batik.transcoder.image.ImageTranscoder so it built and drew the image but didn't save it, just made it available on a public interface.
/Transcoder t = new PNGTranscoder();/
/TranscoderInput input = new TranscoderInput( url.toString() );/
// /ByteArrayOutputStream ostream = null;/
// /ostream = new ByteArrayOutputStream();
TranscoderOutput output = new TranscoderOutput( ostream );/
// /t.transcode( input, output );
ostream.flush();
ostream.close();/
// /byte[] imgData = ostream.toByteArray();
Image img = Toolkit.getDefaultToolkit().createImage( imgData );/
/ / Now using this code for loading 100 images, it is very slow and takes up a lot of resources.
Over 60% of the CPU power is used for the transcode() method, 40% of which goes to ImageTranscoder.transcode() and
20% SAX parsing.
This seems to be a tad bit too much.
Any advice or other solutions?
Tanel Suurhans
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
