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 Raymond Law <ra...@yahoo.com> on 2007/03/29 21:49:13 UTC

Transcoder API example

I am trying the first Transcoder API example with the following code:

import java.io.*;

import org.apache.batik.transcoder.image.JPEGTranscoder;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;

public class SaveAsJPEG {

    public static void main(String[] args) throws Exception {

        // Create a JPEG transcoder
        JPEGTranscoder t = new JPEGTranscoder();

        // Set the transcoding hints.
        t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY,
                             new Float(.8));

        // Create the transcoder input.
        String svgURI = new File(args[0]).toURL().toString();
        System.out.println("svgURI = " + svgURI);
        TranscoderInput input = new TranscoderInput(svgURI);

        // Create the transcoder output.
        OutputStream ostream = new FileOutputStream("out.jpg");
        TranscoderOutput output = new TranscoderOutput(ostream);

        // Save the image.
        t.transcode(input, output);

        // Flush and close the stream.
        ostream.flush();
        ostream.close();
        System.exit(0);
    }
}

But I got the following error:

200 rlaw ~/downloads/batik-1.6/test > java SaveAsJPEG batikYin.svg 
svgURI = file:/home/rlaw/downloads/batik-1.6/test/batikYin.svg
Exception in thread "main" java.lang.NullPointerException
        at java.io.Reader.<init>(Reader.java:61)
        at java.io.InputStreamReader.<init>(InputStreamReader.java:80)
        at java.util.Properties.load(Properties.java:266)
        at org.apache.batik.util.XMLResourceDescriptor.getParserProps(Unknown Source)
        at org.apache.batik.util.XMLResourceDescriptor.getXMLParserClassName(Unknown Source)
        at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(Unknown Source)
        at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(Unknown Source)
        at SaveAsJPEG.main(SaveAsJPEG.java:28)
201 rlaw ~/downloads/batik-1.6/test > 

batikYin.svg is from xml-batik/samples and is in the same directory as SaveAsJPEG.class.  What could I be missing?

Ray,





 
____________________________________________________________________________________
Sucker-punch spam with award-winning protection. 
Try the free Yahoo! Mail Beta.
http://advision.webevents.yahoo.com/mailbeta/features_spam.html

Re: Transcoder API example

Posted by Selva <se...@yahoo.co.in>.
Hi Ray,

It seems your environment may not have resources directory or 
XMLResourceDescriptor.properties file under util directory.

Thanks,
Selva


Raymond Law wrote:
> 
> I am trying the first Transcoder API example with the following code:
> 
> import java.io.*;
> 
> import org.apache.batik.transcoder.image.JPEGTranscoder;
> import org.apache.batik.transcoder.TranscoderInput;
> import org.apache.batik.transcoder.TranscoderOutput;
> 
> public class SaveAsJPEG {
> 
>     public static void main(String[] args) throws Exception {
> 
>         // Create a JPEG transcoder
>         JPEGTranscoder t = new JPEGTranscoder();
> 
>         // Set the transcoding hints.
>         t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY,
>                              new Float(.8));
> 
>         // Create the transcoder input.
>         String svgURI = new File(args[0]).toURL().toString();
>         System.out.println("svgURI = " + svgURI);
>         TranscoderInput input = new TranscoderInput(svgURI);
> 
>         // Create the transcoder output.
>         OutputStream ostream = new FileOutputStream("out.jpg");
>         TranscoderOutput output = new TranscoderOutput(ostream);
> 
>         // Save the image.
>         t.transcode(input, output);
> 
>         // Flush and close the stream.
>         ostream.flush();
>         ostream.close();
>         System.exit(0);
>     }
> }
> 
> But I got the following error:
> 
> 200 rlaw ~/downloads/batik-1.6/test > java SaveAsJPEG batikYin.svg 
> svgURI = file:/home/rlaw/downloads/batik-1.6/test/batikYin.svg
> Exception in thread "main" java.lang.NullPointerException
>         at java.io.Reader.<init>(Reader.java:61)
>         at java.io.InputStreamReader.<init>(InputStreamReader.java:80)
>         at java.util.Properties.load(Properties.java:266)
>         at
> org.apache.batik.util.XMLResourceDescriptor.getParserProps(Unknown Source)
>         at
> org.apache.batik.util.XMLResourceDescriptor.getXMLParserClassName(Unknown
> Source)
>         at
> org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(Unknown
> Source)
>         at
> org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(Unknown
> Source)
>         at SaveAsJPEG.main(SaveAsJPEG.java:28)
> 201 rlaw ~/downloads/batik-1.6/test > 
> 
> batikYin.svg is from xml-batik/samples and is in the same directory as
> SaveAsJPEG.class.  What could I be missing?
> 
> Ray,
> 
> 
> 
> 
> 
>  
> ____________________________________________________________________________________
> Sucker-punch spam with award-winning protection. 
> Try the free Yahoo! Mail Beta.
> http://advision.webevents.yahoo.com/mailbeta/features_spam.html
> 

-- 
View this message in context: http://www.nabble.com/Transcoder-API-example-tf3488567.html#a9743559
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