SVG (Scalable Vector Graphics) is a popular format for creating and displaying vector graphics on the web. SVG images can be scaled, rotated, and transformed without losing quality or resolution. However, if you are using Delphi or C++ Builder to develop cross-platform applications with FireMonkey, you may find it challenging to convert your canvas drawing to SVG format.
Fortunately, there is a library that can help you with this task: Winsoft SVG Canvas for FireMonkey[^1^]. This library allows you to convert any canvas drawing to SVG format with just a few lines of code. It supports Windows, macOS, Linux, iOS and Android platforms, and it comes with source code included in the registered version. You can also distribute your applications that use this library royalty free.
In this article, we will show you how to use Winsoft SVG Canvas for FireMonkey to create and save an SVG image from a canvas drawing. We will use Delphi 10.2 Tokyo as our IDE, but you can also use C++ Builder or any other supported version of Delphi or C++ Builder.
The first step is to download and install Winsoft SVG Canvas for FireMonkey from the official website[^1^]. You can try the trial version for free, or purchase a license for one developer ($40 USD) or for all developers in your company ($120 USD). You can also order year upgrades for registered users ($20 USD) or multi-license users ($60 USD).
After downloading the zip file, extract it to a folder of your choice. You will find two folders inside: Packages and Source. The Packages folder contains the compiled packages for different versions of Delphi and C++ Builder. The Source folder contains the source code of the library.
To install the library, open the package file that matches your IDE version (for example, SvgCanvasFMX260.dproj for Delphi 10.2 Tokyo) in your IDE. Then, right-click on the project node in the Project Manager and select Install. This will compile and install the package into your IDE.
The next step is to create a new FireMonkey application in your IDE. To do this, go to File > New > FireMonkey Application - Delphi (or C++ Builder). Choose Blank Application as the template and click OK.
This will create a new project with a blank form. You can change the form properties as you like, such as the caption, size, position, etc. For this example, we will use the default settings.
Now we need to add a TCanvas object to our form. This object will allow us to draw on the form using various methods and properties. To add a TCanvas object, go to Tool Palette > System > TCanvas and drag it onto the form.
You can change the name of the TCanvas object if you want, but we will use the default name Canvas for this example. You don't need to change any other properties of the TCanvas object.
The next step is to draw something on the canvas using its methods and properties. You can use any of the available methods and properties of TCanvas, such as Fill, Stroke, Font, DrawLine, DrawRect, DrawEllipse, FillText, etc. For this example, we will draw a simple red ellipse with a black border and some text inside it.
To draw on the canvas, we need to write some code in the OnCreate event handler of the form. To do this, double-click on an empty area of the form to open the Code Editor. Then, add the following code: