Why does Batik creates BufferedImage slowly then PNG?

Discussion in 'Java' started by Evgrafov, Apr 21, 2006.

  1. Evgrafov

    Evgrafov Guest

    Hi there.
    Recently i've tried to create BufferedImage from SVG content. I used a
    documented method which is described on Batik's site:

    public static BufferedImage getImageFromSvg(SVGDocument document,
    Dimension dimension)
    throws IOException
    {
    // Load SVG resource into a document


    // Build the tree and get the document dimensions
    UserAgentAdapter userAgentAdapter = new UserAgentAdapter();
    BridgeContext bridgeContext = new
    BridgeContext(userAgentAdapter);
    GVTBuilder builder = new GVTBuilder();
    GraphicsNode graphicsNode =
    builder.build(bridgeContext,document);

    // Paint svg into image buffer
    BufferedImage bufferedImage = new
    BufferedImage(dimension.width,dimension.height,
    BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = (Graphics2D) bufferedImage.getGraphics();
    graphicsNode.paint(g2d);

    // Cleanup and return image
    g2d.dispose();
    return bufferedImage;
    }
    ...........................................
    startTime = System.currentTimeMillis();
    BufferedImage bim = getImageFromSvg(document,new
    Dimension(Integer.parseInt(args[1]),Integer.parseInt(args[2])));
    endTime = System.currentTimeMillis();
    System.out.println("BufferedImage from SVG:
    "+(endTime-startTime));



    Then i used PNGTranscoder to create the png content based on the same
    SVG document. I used the following method:

    baos = new ByteArrayOutputStream();
    PNGTranscoder pngtr = new PNGTranscoder();
    pngtr.addTranscodingHint(PNGTranscoder.KEY_AOI,new
    Rectangle(0,0,new Integer(args[1]).intValue(),new
    Integer(args[2]).intValue()));
    //pngtr.addTranscodingHint(PNGTranscoder.KEY_MAX_HEIGHT,new
    Float(50.0));
    //pngtr.addTranscodingHint(PNGTranscoder.KEY_MAX_WIDTH,new
    Float(50.0));
    pngtr.addTranscodingHint(PNGTranscoder.KEY_HEIGHT,new
    Float(args[1]));
    pngtr.addTranscodingHint(PNGTranscoder.KEY_WIDTH,new
    Float(args[2]));
    try {
    startTime = System.currentTimeMillis();
    pngtr.transcode(new TranscoderInput(document),new
    TranscoderOutput(baos));
    endTime = System.currentTimeMillis();
    } catch (TranscoderException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    System.out.println("PNG from SVG: "+(endTime-startTime));

    The program outputs:
    BufferedImage from SVG: 2016
    PNG from SVG: 547

    I wonder that SVG->BufferedImage is almost four times slowly then
    SVG->PNG. Does anyone there can explain why? It is very critical for my
    application. I would prefere BufferedImage rather then PNG. But that
    performance is realy annoys me.

    Thanks.
    Evgrafov.
     
    Evgrafov, Apr 21, 2006
    #1
    1. Advertising

  2. Evgrafov

    snipg

    Joined:
    Oct 3, 2012
    Messages:
    1
    Hi Evgrafov,

    I am also having performance issues with Batik. Were you able to solve this issue? If so , could you please let me know how you solved it.

    Thanks
     
    snipg, Oct 3, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Yuriy

    Why Java Script slowly

    Yuriy, Aug 26, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    276
    Mark Fitzpatrick
    Aug 26, 2003
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,996
    Smokey Grindel
    Dec 2, 2006
  3. Replies:
    0
    Views:
    473
  4. Replies:
    0
    Views:
    296
  5. Replies:
    4
    Views:
    546
    cwdjrxyz
    Jan 17, 2006
Loading...

Share This Page