You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Kayser <ko...@yahoo.com> on 2011/11/17 12:06:40 UTC

Convert into PNG on the fly

I try to convert an svg into PNG. the svg document is coming from a server as
a Inputstream.
First, I convert the svg stream into byte array with:

     byte[] streamBytes = IOUtils.toByteArray(svgStream);

Then i convert the bytes into outputstream(PNG).    

private ByteArrayOutputStream svgToPng(byte[] streamBytes)
                                            throws TranscoderException,
IOException {
        PNGTranscoder t = new PNGTranscoder();
        TranscoderInput input = new TranscoderInput(new
ByteArrayInputStream(streamBytes));
        ByteArrayOutputStream ostream = new ByteArrayOutputStream();
        TranscoderOutput output = new TranscoderOutput(ostream);

        t.transcode(input, output);

        ostream.flush();
        // ostream.close();
        return ostream;
    }

Note: If i save the svgstream on th disk and use the following
transcoderinput with uri constructor, then it works. But in my case i don't
want to save on the disk.

TranscoderInput input = new TranscoderInput(new
File("c:/a.svg").toURI().toString());


--
View this message in context: http://batik.2283329.n4.nabble.com/Convert-into-PNG-on-the-fly-tp4079626p4079626.html
Sent from the Batik - Users mailing list archive at Nabble.com.

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


Re: Convert into PNG on the fly

Posted by Jim Blackler <ji...@gmail.com>.
What's your question Kayser?

On 17 November 2011 11:06, Kayser <ko...@yahoo.com> wrote:

> I try to convert an svg into PNG. the svg document is coming from a server
> as
> a Inputstream.
> First, I convert the svg stream into byte array with:
>
>     byte[] streamBytes = IOUtils.toByteArray(svgStream);
>
> Then i convert the bytes into outputstream(PNG).
>
> private ByteArrayOutputStream svgToPng(byte[] streamBytes)
>                                            throws TranscoderException,
> IOException {
>        PNGTranscoder t = new PNGTranscoder();
>        TranscoderInput input = new TranscoderInput(new
> ByteArrayInputStream(streamBytes));
>        ByteArrayOutputStream ostream = new ByteArrayOutputStream();
>        TranscoderOutput output = new TranscoderOutput(ostream);
>
>        t.transcode(input, output);
>
>        ostream.flush();
>        // ostream.close();
>        return ostream;
>    }
>
> Note: If i save the svgstream on th disk and use the following
> transcoderinput with uri constructor, then it works. But in my case i don't
> want to save on the disk.
>
> TranscoderInput input = new TranscoderInput(new
> File("c:/a.svg").toURI().toString());
>
>
> --
> View this message in context:
> http://batik.2283329.n4.nabble.com/Convert-into-PNG-on-the-fly-tp4079626p4079626.html
> Sent from the Batik - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>