/* compilation command: g++ -std=c++11 -Wall -o gdk-pixbuf-demo `pkg-config --cflags --libs gdk-pixbuf-2.0` gdk-pixbuf-demo.cpp */ #include int main() { unsigned int width = 96; unsigned int height = 96; GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, width, height); int n_channels = gdk_pixbuf_get_n_channels(pixbuf); int rowstride = gdk_pixbuf_get_rowstride(pixbuf); guchar* pixels = gdk_pixbuf_get_pixels(pixbuf); for (unsigned int i = 0; i < height; ++i) { for (unsigned int j = 0; j < width; ++j) { guchar* pp = pixels + i * rowstride + j * n_channels; if ((i / (height/8) + j / (width/8)) % 2 == 0) { pp[0] = 25; /* red */ pp[1] = 7; /* green */ pp[2] = 26; /* blue */ } else { pp[0] = 248; /* red */ pp[1] = 201; /* green */ pp[2] = 95; /* blue */ } } } gdk_pixbuf_save(pixbuf, "output.jpg", "jpeg", nullptr, "quality", "100", nullptr); }