Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display svg on canvas

I want to display some images on a canvas accordingly to screen dimension without losing the image resolution.

If I use a simple png or jpeg, I will see the image pixelized on a big screen.

What I am thinking is to use svg files and display them on the janvas. Is something like that possible? (I tried to use Apache Batik without a possitive result)

if this is not possible, can you think any other alternative?

like image 273
Giannis Tzagarakis Avatar asked Sep 27 '22 03:09

Giannis Tzagarakis


1 Answers

Apache Commons has Batik Swing component containing special canvas JSVGCanvas. This is the best approach you can find.

The goal of the Batik Swing component module is to provide a Swing component that can used to display SVG documents. With the JSVGCanvas class, you can easily display an SVG document (from a URI or a DOM tree) and allow the user to manipulate it, such as rotating, zooming, panning, selecting text or activating hyperlinks.


I tried to use Apache Batik without a possitive result

Any problem you can share with us? Here and here you will find how to implement it.

public SVGCanvasDemo(JFrame frame) {
    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add("Center", svgCanvas);
    frame.setVisible(true);
    svgCanvas.setURI("file:/c:/files/hungryminds/rectangles.svg");
}
like image 179
Jordi Castilla Avatar answered Nov 13 '22 06:11

Jordi Castilla