xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From EUBanana <cpsci...@googlemail.com>
Subject Batik rendering issues
Date Tue, 25 Nov 2008 15:09:41 GMT

Hi all - apologies in advance for the huge images but its probably the
easiest way to explain.

I'm attempting to use Batik to modify an existing application to handle SVG
files.  The app at the moment handles raster graphics, and it works with
BufferedImage objects which have various transformations applied to them.

I can't use a Batik JSVG canvas then, because I need to turn it into an
Image to work with the existing code.  On the other hand, I don't want to
rasterise the SVG immediately because I want the transforms to act upon the
SVG graphics before it is rasterised, so the image stays nice and crisp when
you zoom in.  The only way I could find to do this transform was using the
JSVGCanvas, I couldn't see in the various bridge classes how to do a
transformation before rasterising?  Certainly I tried with the UserAgent
class but it didn't seem to do anything.

I wrote up some test harness code to see how this flies - the bit that
handles the rendering is below.

currentTX is the AffineTransform to apply.
The application has two frames (really naff code but its only a test rig :)
), and in one frame it displays the JSVGCanvas of the SVG image with the
transform applied, and in the other frame it displays the image but in the
form of a BufferedImage which is created from the JSVGCanvas.  The desired
output is that they both look the same - so I can use the BufferedImage copy
of the JSVGCanvas in this application.

        public void paint(Graphics g) {
            g.fillRect(0, 0, this.getWidth(), this.getHeight());
            Graphics2D g2 = (Graphics2D) g;

            try {
                if (backbuffer.validate(g2.getDeviceConfiguration()) ==
VolatileImage.IMAGE_OK && changed == false) {
                    g2.drawImage(backbuffer, 0, 0, this);
                } else {
                    g2.drawImage(backbuffer, 0, 0, this);

            } catch (NullPointerException e) {


        public void paintComponent(Graphics g) {
            g.fillRect(0, 0, this.getWidth(), this.getHeight());

        private void createBackBuffer() {
            if (backbuffer != null) {
                backbuffer = null;
            backbuffer = createVolatileImage(getWidth(), getHeight());

        boolean test = true;
        public void reRender() {
            if (backbuffer == null) {
            if(test) {
                JFrame frame = new JFrame("JSVG Canvas Image");
                frame.setPreferredSize(new Dimension(800,800));
                frame.setLocation(0, 0);
                test = false;
            } else {
            Graphics2D g2 = (Graphics2D) backbuffer.getGraphics();
            Image img = this.createImage(getWidth(), getHeight());
            Graphics2D gimg = (Graphics2D) img.getGraphics();
            gimg.fill3DRect(0, 0, 500, 500, true);
            g2.drawImage(img, new AffineTransform(), this);

The problem is that while sometimes it renders perfectly, as the transform
changes various parts of the SVG image fail to be drawn onto the
BufferedImage and you get weird effects.  The most common thing is for the
text elements to be missing, but sometimes it misses out other parts of the
image too.  This isn't a predictable thing, it doesn't seem to be
replicatable per se - sometimes a given transform will work, sometimes it
won't!  The first screenshot shows it working as intended, the second shows
it with a problem...

Are there any ideas?  I'm new to Batik so appreciate I may be doing this
totally wrong.


View this message in context: http://www.nabble.com/Batik-rendering-issues-tp20682211p20682211.html
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

View raw message