The SVG file is a two-dimensional vector image based on documents in XML format. The SVG format is used not only for the description of two-dimensional vector graphics, but also for mixed vector-raster images.
Let's list the main advantages of SVG format:
First of all, as previously mentioned in the last article, vector graphics are scaled up or down without loss of quality (and when enlarged, the image doesn’t turn into the cubism art).
Second, SVG is fully compatible with web technologies and therefore will be an organic part of any web-site.
Forth, SVG files are considered text, so you can optimize the file for SEO without external meta tags by directly adding keywords to the image code.
This format has some disadvantages, too:
- The file size will rapidly increase just like an avalanche when increasing the detailing of images. However, for images with a bunch of details, it is best to use PNG of JPG formats.
So, unfortunately, SVG is completely unsuitable for realistic high-resolution photographs and detailed maps of the area.
- SVG is not supported by older browsers (Internet Explorer 8 and older), but I don’t think this is a great disadvantage.
- By default, (for example, WordPress), doesn’t allow you to upload SVG files, due to security issues. WordPress perceives this extension as something malicious and therefore blocks it. But you can bypass this block using plugins.
- SVG is suitable for creating simple objects that can be described by simple figures or their parts.
- We should also mention that social networks, such as Facebook and Twitter, do not support SVG format. If you use SVG files as thumbnails, you will have to use the plugin and set PNG or JPG for meta tags.
We reviewed the main advantages and disadvantages of the SVG format and now we can return to the main topic of this article.
How to save a SVG file using Delphi or Lazarus?
First you need to create the image!
And then I can advise (all of a sudden) FastReport VCL, because using it you can save immediately in the desired format from Delphi. After all, there might be many objects to display apart from the pictures. It’s convenient – so, why not? From barcodes to tables and maps, it’s strongly recommended to save them in a vector format!
Therefore, let’s begin!
Create a report. Previewed before saving, didn’t like something? Changed, edited! Now, after we created what was required, launch it and see what happened.
Call a preview and select the format we need. Here it is – below! Select and click.
Now we see a window with many different settings. Set up everything we need and click OK!
Briefly about export settings
You can see that when saving in SVG format, the settings are not the same with BMP, JPEG, TIFF or GIF.
More precisely, such functions as:
Styles – saving styles;
Unified Pictures – unifying pictures;
Formatted – saving formatting;
Pictures – saving a document with pictures – this is the right choice for those images that were already pixel when adding to our document;
Multi Page – saving multiple pages;
Page navigator – creating a page navigator;
Saving images in PNG, EMF, BMP and JPEG formats.
And the settings for the BMP, JPEG, TIFF, GIF formats are:
Monochrome – images in shades of black;
Crop pages – whether to crop pages;
JPEG quality – setting the quality of the graphic object;
Resultion (dip) – resolution.
Obviously, a vector image will be rasterized when saved in raster formats, but the opposite (raster to vector) will not happen.
The only things that seem to be common among all these formats are the action settings, ability to save and automatically open the document immediately after saving.
Having considered how to save using the preview window, let’s move on to the saving without a preview.
Saving SVG files using Delphi / C++Builder / Lazarus code
Let’s compare the results of exporting raster and vector objects!
I will provide JPEG and SVG examples below.
And… here we immediately see the difference. Can you find it? :)
Well, for example, a raster image has a larger size than a vector image, and when scaling, the clarity decreases. But as for a vector image (SVG), when scaling, clarity remains the same and the file size is much smaller. The only drawback is that SVG is not suitable for realistic photos (but we don’t have them anyway).
Let’s summarize! The SVG vector format is very convenient (if you use it in the right place), and saving via FastReport VCL makes it simple.