Show svg on canvas

I want to display some images on canvas according to screen size without losing image resolution.

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

I want to use svg files and display them on janvas. Is this possible? (I tried using Apache Batik without a positive result)

If this is not possible, can you think of another alternative?

+5
source share
1 answer

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

The goal of the Batik Swing component is to provide a Swing component that can be used to display SVG documents . With the JSVGCanvas class JSVGCanvas you can easily display an SVG document (from a URI or DOM tree) and allow the user to manipulate it, for example, rotate, scale, pan, select text or activate hyperlinks.


I tried using Apache Batik without a positive 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"); } 
+4
source

Source: https://habr.com/ru/post/1236609/


All Articles