Yes, stb_image_write header can help you there.
https://github.com/nothings/stb/blob/master/stb_image_write.h
Read through the comments at the beginning of the file,
There are five functions, one for each image file format:
int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes);
int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data);
int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);
int stbi_write_jpg(char const *filename, int w, int h, int comp, const void *data, int quality);
int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data); |
The extra argument for PNG refers to the following:
For PNG, "stride_in_bytes" is the distance in bytes from the first byte of
a row of pixels to the first byte of the next row of pixels. |
Here's an example by someone else, with pretty pictures:
http://chanhaeng.blogspot.com/2018/12/how-to-use-stbimagewrite.html
If there's something in particular you don't understand, let us know. It takes some persistence and exploring to understand things, so be prepared for that. Try to just start with small examples, like writing a single red pixel to a file, and then try to work your way up.
The reason I used stbi is because I originally used code from a library called SFML, which also can read/write images.
https://www.sfml-dev.org/documentation/2.5.1/Image_8hpp_source.php
https://github.com/SFML/SFML/blob/master/include/SFML/Graphics/Image.hpp
https://github.com/SFML/SFML/blob/master/src/SFML/Graphics/Image.cpp
https://github.com/SFML/SFML/blob/master/src/SFML/Graphics/ImageLoader.cpp
ImageLoader.cpp is the file that actually uses stbi, which is how I learned to use it.
See the ImageLoader::loadImageFromFile and ImageLoader::saveImageToFile functions.
_______________________________________
There are other libraries people have made, if you don't prefer stbi. For example there's a library called LodePNG that can read/write PNG files.
https://github.com/lvandeve/lodepng
Read through the README on that page for explanation.
+++++++++++++++++++++++++++++++++++
If you're new to C++ or programming in general, I suggest learning just C++/programming before you tackle multimedia stuff like images. But up to you, if you want the challenge. Working with images definitely make some things more fun.