Why does Batik creates BufferedImage slowly then PNG?

E

Evgrafov

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.
 
Joined
Oct 3, 2012
Messages
1
Reaction score
0
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top