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 Kelvin Ho <Ke...@sausage.com> on 2001/02/08 01:04:37 UTC

Question: Graphics ->SVG->JPEG

I try to generate a graphic using Batik and then convert to JPEG but I got 
java.lang.ClassCastException: org.apache.batik.dom.GenericDocument
at org.apache.batik.refiml.transcoder.ImageTranscoder.transcodeToStream
(ImageTranscoder.java:46)
at zeo.transform(zeo.java:450)

Any ideal?

And here is the source code:

        DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
        Document document = domImpl.createDocument(null, "svg", null);
        svgGenerator = new SVGGraphics2D(document);

    svgGenerator.setSVGCanvasSize(new java.awt.Dimension (600,600));
    svgGenerator.setPaint(Color.white);
    svgGenerator.drawLine (100,0,100,700);
    svgGenerator.fill(new Rectangle(10, 10, 100, 100));

      svgGenerator.stream (filename,CSS);

   String mimeType ="image/jpeg";

    TranscoderFactory factory =
ConcreteTranscoderFactory.getTranscoderFactoryImplementation();
    Transcoder t = factory.createTranscoder(mimeType);
    if (t == null) {
      System.out.println ("No transcoder found for mime type : "+mimeType);
      System.exit(1);
    }
    try {
      int k = mimeType.lastIndexOf('/');
      String ext = mimeType.substring(k+1);
      String url = filename.substring(0,filename.indexOf(".svg")) + "." +
ext;

      OutputStream ostream = new BufferedOutputStream(new
FileOutputStream(url));        
// Exception happen here!!!!
      t.transcodeToStream(svgGenerator.getDOMFactory(), ostream);
      ostream.flush();
      ostream.close();
    } catch (Exception e) {
      e.printStackTrace();
    }

Regards
Kelvin




CAUTION - This message may contain privileged and confidential information
intended only for the use of the addressee named above. If you are not the
intended recipient of this message you are hereby notified that any use,
dissemination, distribution or reproduction of this message is prohibited.
If you have received this message in error, please notify the sender
immediately.

Re: Question: Graphics ->SVG->JPEG

Posted by Vincent Hardy <vh...@eng.sun.com>.
Kevin,

Have a look at:

http://www-sop.inria.fr/koala/batik/mlists/batik-users/archives/msg00069.html

there is an example of what you are trying to do. The whole discussion
thread is at:

http://www-sop.inria.fr/koala/batik/mlists/batik-users/archives/threads.html

V.

Kelvin Ho wrote:
> 
> I try to generate a graphic using Batik and then convert to JPEG but I got
> java.lang.ClassCastException: org.apache.batik.dom.GenericDocument
> at org.apache.batik.refiml.transcoder.ImageTranscoder.transcodeToStream
> (ImageTranscoder.java:46)
> at zeo.transform(zeo.java:450)
> 
> Any ideal?
> 
> And here is the source code:
> 
>         DOMImplementation domImpl =
> GenericDOMImplementation.getDOMImplementation();
>         Document document = domImpl.createDocument(null, "svg", null);
>         svgGenerator = new SVGGraphics2D(document);
> 
>     svgGenerator.setSVGCanvasSize(new java.awt.Dimension (600,600));
>     svgGenerator.setPaint(Color.white);
>     svgGenerator.drawLine (100,0,100,700);
>     svgGenerator.fill(new Rectangle(10, 10, 100, 100));
> 
>       svgGenerator.stream (filename,CSS);
> 
>    String mimeType ="image/jpeg";
> 
>     TranscoderFactory factory =
> ConcreteTranscoderFactory.getTranscoderFactoryImplementation();
>     Transcoder t = factory.createTranscoder(mimeType);
>     if (t == null) {
>       System.out.println ("No transcoder found for mime type : "+mimeType);
>       System.exit(1);
>     }
>     try {
>       int k = mimeType.lastIndexOf('/');
>       String ext = mimeType.substring(k+1);
>       String url = filename.substring(0,filename.indexOf(".svg")) + "." +
> ext;
> 
>       OutputStream ostream = new BufferedOutputStream(new
> FileOutputStream(url));
> // Exception happen here!!!!
>       t.transcodeToStream(svgGenerator.getDOMFactory(), ostream);
>       ostream.flush();
>       ostream.close();
>     } catch (Exception e) {
>       e.printStackTrace();
>     }
> 
> Regards
> Kelvin
> 
> CAUTION - This message may contain privileged and confidential information
> intended only for the use of the addressee named above. If you are not the
> intended recipient of this message you are hereby notified that any use,
> dissemination, distribution or reproduction of this message is prohibited.
> If you have received this message in error, please notify the sender
> immediately.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org