xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thierry Kormann <tkorm...@ilog.fr>
Subject Re: Render SVG as a BufferedImage
Date Thu, 20 Dec 2001 15:30:21 GMT
On Thursday 20 December 2001 16:16, Thierry Kormann wrote:
>
> The following code is not really optimal as you encode the image in png and
> then decode it. Another way to implement that would be to subclass the
> ImageTranscoder such as (live code so might not work :):
>
> import org.apache.batik.transcoder.*;
> import org.apache.batik.transcoder.image.ImageTranscoder;
>
> public class Foo {
>
>   public static Image transcodeSVGDocument( URL url, int x, int y ){
>
>      // Create a custom transcoder.



      MyImageTranscoder t = new MyImageTranscoder();

>
>      // Set the transcoding hints.
>      t.addTranscodingHint( PNGTranscoder.KEY_WIDTH,  new Float(x) );
>      t.addTranscodingHint( PNGTranscoder.KEY_HEIGHT, new Float(y) );
>
>      // Create the transcoder input.
>      TranscoderInput input = new TranscoderInput( url.toString() );
>      t.transcode(input, null);
>
>      return t.getBufferedImage();
>   }
>
>   static class MyImageTranscoder extends ImageTranscoder {
>
>     protected BufferedImage img;
>
>     public void writeImage(BufferedImage img, TranscoderOutput output)
>         throws TranscoderException {
>         this.img = img; // just store the image
>     }
>
>     public BufferedImage getBufferedImage() {
>         return img;
>     }
>   }
> }
>

PS: Still live code :)

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


Mime
View raw message