The SvgImage class represents an SVG graphic that is loaded from a file into memory. You can create this class and receive a new SVG document:
Dim hSvgImage As SvgImage hSvgImage = New SvgImage ( [ Width As Float, Height As Float ] )
Width and Height are the dimensions of the SVG document in points. If they are not specified, they must be specified later before you can draw on them. The actual dimension of the SVG document is calculated by assuming a resolution of 72 DPI.
The free open source editor Inkscape has the best support for SVG. At https://inkscape.org/de/entwickeln/das-svg-format/ you will find a simple description of the SVG format:
SVG (abbreviation for “Scalable Vector Graphics”) is a free, open source, standardised file format for vector graphics. It is developed and maintained by the W3C (World Wide Web Consortium), the most important international standardisation body for the Internet. It is based on XML (Extensible Markup Language), also a W3C standard format, which is a generic markup language developed to represent any data in a human- and machine-readable format.
If you use the following (XML) text
<svg xmlns="http://www.w3.org/2000/svg" width="300" height="200"> <rect x="50" y="50" width="200" height="100" style="fill:red"/> </svg>
into the empty file red.svg using a text editor, you will see the following display - for example with the image viewer XViewer:
Figure 23.4.1.1: Display of the red.svg file
The SvgImage class only has two properties:
Property | Data type | Description |
---|---|---|
Height | Float | Returns or sets the height of the SVG document in points. A synonym for the height property is H. |
Width | Float | Returns or sets the width of the SVG document in points. A synonym for the Width property is W. |
Table 23.4.1.1.1 : Properties of the SvgImage class
The SvgImage class provides you with the following four methods:0
Method | Description |
---|---|
Clear() | Deletes the SVG image (in memory). |
Paint ( [ X As Float, Y As Float, Width As Float, Height As Float ] ) | Draws the SVG image on the current drawing area (device). |
Resize ( Width As Float, Height As Float ) | Changes the size of the SVG image. Width is its new width in points. Height is its new height in points. |
Save ( Path As String ) | Saves the SVG image in the specified file path as an SVG file. |
Table 23.4.1.2.1 : Methods of the SvgImage class
The following static method loads an SVG document from the file with the specified file path and returns it as a new SVGImage:
Static Function Load ( Path As String ) As SvgImage
Example 1
Public Sub DrawingArea1_Draw()
'-- Paint the Gambas logo Dim hSvgImage As SvgImage ' (1) hSvgImage = SvgImage.Load("gambas.svg") ' (2) hSvgImage.Paint() ' (3) End
Example 2 - Drawing is performed on an SVG image and the modified image is saved.
Dim hSvgImage As SvgImage hSvgImage = SvgImage.Load("~/gambas.svg") Paint.Begin(hSvgImage) Paint.Brush = Paint.RadialGradient(200, 140, 40, 215, 115, [Color.RGB(255, 0, 0, 64), Color.White], [1.0, 0.1]) Paint.Arc(200, 140, 40) Paint.Fill() Paint.End() hSvgImage.Save("~/gambas_with_red_ball.svg")
Note: Qt's SVG support has had some bugs for years. It is not known whether it will be better with Qt5.