Search code examples
javasvgscalingpixelbatik

Seeing pixels of a SVG file when scaling in Java


I am handling a SVG file in Java using Batik library. The problem occurs when i scale it. I can see pixels of lines. Off course this should not happen, i should be able to zoom at least about 4000% and maintain the smoothness.

SVG file is read from an extended class, and it is painted from an override paint method. First i set new scale to AffineTransform variable, apply this to graphics of the method and paint using super.paint().

I am really stuck and can't figure out the problem. SVG files I am using are ok, I opened them in Inkscape and could zoom without the pixels showing. Please help.

code:

@Override
public void paint(Graphics g) {
  try {
    rad = (int)(radInit*zoom);
    updateTransform();

    Graphics2D g2d = (Graphics2D) g;
    g2d.setTransform(transform);

    super.paint(g);
    paintElements(g2d);
  } catch(NullPointerException nulle) {
    // System.out.println("SVG not loaded yet");
  }
}

private void updateTransform(){
  transform = new AffineTransform();
  transform.translate((-1)*zoom*centarX, (-1)*zoom*centarY);
  transform.scale(zoom, zoom);                      
}

Solution

  • What was needed was

    this.setRenderingTransform(transform, true);
    

    This way no pixels can be seen or rather, everything is painted as it should be.