Site icon Learn C++

How To Use The SVG Image Format With Skia In C++ Builder

How To Use The SVG Image Format With Skia In C++ Builder

The latest RAD Studio / C++ Builder 12 comes with a lot of new features, one of them is Skia graphics library support in C++. Skia is an open-source graphic library that provides support for a variety of hardware and software platforms. Skia provides smooth 2D graphics that uses GPU efficiently. Skia supports a lot of new image formats, such as .bmp, .jpg, .gif, .gif animation, .svg, .ico, .webp, .wbmp and raw images (.arw, .cr2, .dng, .nef, .nrw, .orf, .raf, .rw2, .pef and .srw). It is very useful for handling the SVG image format which is a Scalable Vector Graphics form. In this post we explain how to use SVG images with Skia in C++ Builder.

What is Skia in modern C++?

Skia is an open-source graphic library that provides support variety of hardware and software platforms. Skia is sponsored and managed by Google but is available for use by anyone under the BSD Free Software License. Mainly designed for Google Chrome and ChromeOS, Android, Flutter, Mozilla Firefox and Firefox OS, and many other products. The core components are done by the Skia development team but they consider contributions from any source.

How to use the SVG Image format with Skia in the C++ Builder IDE?

Skia supports a lot of new image formats, such as .bmp, .jpg, .gif, .gif animation, .svg, .ico, .webp, .wbmp, and raw images (.arw, .cr2, .dng, .nef, .nrw, .orf, .raf, .rw2, .pef and .srw). If you want to use SVG image format in your applications, C++ Builder has a TSKSvg Skia component for this, first, you should drag it from the Palette window to your form design.

Then you can double click to SkSvg1 object on your form design, this will open SVG Editor. Click to Open button to select and load a SVG file. Some sample SVG examples can be found in C:\Users\Public\Documents\Embarcadero\Studio\23.0\Samples\Assets folder if you installed Samples in RAD Studio 12.

How to use the SVG Image format with Skia in C++ Builder code?

If you want to use SVG image format in your code first you should have TSkSvg object on your form design, or you can create a new TSkSvg object as below.

[crayon-664851294f2dc602757238/]

Then you can read svg file as below,

[crayon-664851294f2e9807723881/]

If you need, you can change its Wrap mode as shown below.

[crayon-664851294f2eb303003122/]

If you want to make it in a single color, you can override its color to a single color like so:

[crayon-664851294f2ed668532400/]

SVG files may include different DOM objects in a drawing. You can do more specific operations to each of DOM objects in your SVG file. Here’s an example.

[crayon-664851294f2ef280383167/]

Is there a full example of how to use SVG Image format with Skia in C++ Builder code?

In C++ Builder 12, first drag a TSkSvg Skia component on your form design. Now you can load an image when the form is constructed. Here is a full simple example in C++.

[crayon-664851294f2f0653183208/]

If you want to see more Skia examples, please install the latest RAD Studio / C++ Builder12.1 full or trial version and check this sample in the Samples folder:
C:/Users/Public/Documents/Embarcadero/Studio/23.0/Samples/CPP/Multi-Device Samples/Skia4Delphi project. It has many examples that runs different Skia graphical examples. [Editor’s note: due to the way the blogging software works you will need to reverse the slashes shown in the path]

C++ Builder is the easiest and fastest C and C++ compiler and IDE for building simple or professional applications on the Windows operating system. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for UIs.

There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise versions of C++ Builder and there is a trial version you can download from here.

Exit mobile version