PNG images are capable of supporting multiple image properties such as multiple colors, degree of transparency, Gamma correction, Lossless compression, etc. PNG images are widely used and preferred for numerous types of images.
For working with PNG files we will be using the PNGwriter platform-independent, wrapper open-source C++ library for libpng(PNG reference library) one of the most feature-rich library, written in C. PNGwriter library works on Linux, Unix, macOS, and Windows. Its supported features include opening existing PNG images, plotting and reading pixels in the RGB, HSV, and CMYK color spaces, basic shapes, scaling, bilinear interpolation, full TrueType antialiased and rotated text support, and Bezier curves. It requires the FreeType2 library for text support.
For more documentation and libraries visit SourceForge, PNGwriter-github.
How images are generated:
Pixels are the smallest unit that collectively generates an image. Each pixel has some numeric value which represents a color. Below are the steps:
- We choose the desired height and width of the image.
- In the desired, we iterate and apply colors pixel by pixel.
- This collection of pixels is then stored with proper extension and properties, hence generating an image.
Below is the program which generates the RGBA portal graphic images in C++:
The above program takes width, height, and file address with a file name. The pngwriter class represents a PNG image. The constructor of the PNG image allows us to set the width and height in pixels, a background colour, and the path to the file where the image should be saved. As illustrated in the above code, we just arranged three solid colors side-by-side and for that, we used filledsquare() function which has taken the x-y coordinates value from start to end positions and a colour values (R, G, B). When the image is saved in memory, then call the close() method to save it to a disk file.