The latest RAD Studio / C++ Builder 12 comes with a lot of new features, one of which is Skia graphics library support in C++. Skia is an open-source graphic library that provides to support 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 also provides excellent support for the SVG image format which is a Scalable Vector Graphics form. In this post, we explain about the image support added by the inclusion of Skia in C++ Builder and how you can use that support in your own programs and apps.
Table of Contents
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 Skia Images in C++ Builder?
How to load WebP image into a TImage in C++?
The new C++ Builder 12 allows you to use modern 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). Here is how you can load a webp image,
1 2 3 |
Image1->Bitmap->LoadFromFile("C:\\Users\\Public\\Documents\\Embarcadero\\Studio\\23.0\\Samples\\Assets\\rocket.webp"); |
How to load an encoded image from a file in C++?
The new C++ Builder 12 allows you to load encoded image formats from a file, such as a WEBP or JPEG image as in example below,
1 2 3 |
auto LImage = TSkImage::MakeFromEncodedFile("C:\\Users\\Public\\Documents\\Embarcadero\\Studio\\23.0\\Samples\\Assets\\rocket.webp"); |
How to encode an image from a SkImage in C++?
The new C++ Builder 12 allows you to encode image formats from a file, such as a WEBP or JPEG image as in example below,
1 2 3 4 5 |
static const int Quality = 80; TBytes LBytesWebP = LImage->Encode(TSkEncodedImageFormat::WEBP, Quality); TBytes LBytesJpeg = LImage->Encode(TSkEncodedImageFormat::JPEG, Quality); |
How to load animated gif images in C++?
The new C++ Builder 12 allows you to load animated gifs from a file, to display them in animation, you should drag TSkAnimatedImage from palette, then you can write this code to load an animated gif
1 2 3 |
SkAnimatedImage1->LoadFromFile("C:\\Users\\Public\\Documents\\Embarcadero\\Studio\\23.0\\Samples\\Assets\\animated.gif"); |
If you want to see more examples, please install the latest RAD Studio / C++ Builder 12.1 full or trial version and check this sample in 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.
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.