Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Why does Batik creates BufferedImage slowly then PNG?

Reply
Thread Tools

Why does Batik creates BufferedImage slowly then PNG?

 
 
Evgrafov
Guest
Posts: n/a
 
      04-21-2006
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_HEI GHT,new
Float(50.0));
//pngtr.addTranscodingHint(PNGTranscoder.KEY_MAX_WID TH,new
Float(50.0));
pngtr.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, new
Float(args[1]));
pngtr.addTranscodingHint(PNGTranscoder.KEY_WIDTH,n ew
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.

 
Reply With Quote
 
 
 
 
snipg snipg is offline
Junior Member
Join Date: Oct 2012
Posts: 1
 
      10-03-2012
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
How does one play a .wav file and then another and then another...? ted.j.conway@gmail.com Javascript 4 01-17-2006 03:28 AM
Help. SessionID is x then y then x then y BodiKlamph@gmail.com ASP General 0 09-03-2005 03:02 PM
Why does my site load up slowly? philip.wylie2 Computer Support 8 12-17-2003 11:21 PM



Advertisments