6#include "png++/png.hpp"
17 const auto width =
static_cast<png::uint_32
>(image.
width());
18 const auto height =
static_cast<png::uint_32
>(image.
height());
20 png::image<png::rgba_pixel> png{width, height};
22 for (std::size_t row = 0; row < image.
height(); ++row) {
23 for (std::size_t col = 0; col < image.
width(); ++col) {
24 const auto pixel = image.
at(row, col);
25 png[row][col] = png::rgba_pixel{pixel.red(), pixel.green(), pixel.blue(), pixel.alpha()};
30 png.write(path.string());
32 catch (
const std::exception &e) {
33 return FormattableError{std::format(
"{}: save failed: {}", path.filename().c_str(), e.what())};
A template for two-dimensional images with arbitrarily typed pixel values.
std::size_t width() const
std::size_t height() const
PixelType at(std::size_t i) const
Fetches the pixel value at a given one-dimensional pixel index.
virtual ChainableResult< void > save_to_file(const Image< Rgba32 > &image, const std::filesystem::path &path) const