Use gdk_pixbuf_save() with the pixbuf, destination filename, and explicit output format such as "png". Check its return value and handle the GError on failure. Save formats and options depend on the GdkPixbuf installation and the selected format.
Save a GdkPixbuf to a named file
The basic call takes a GdkPixbuf, filename, format name, error output, and optional format-specific key/value options. Finish the options with NULL, including when there are no options.
As an Amazon Associate I earn from qualifying purchases.
#include <gdk-pixbuf/gdk-pixbuf.h>
GError *error = NULL;
gboolean saved = gdk_pixbuf_save(
pixbuf,
"output.png",
"png",
&error,
NULL
);
if (!saved) {
g_printerr("Could not save image: %sn", error->message);
g_error_free(error);
}
The function returns TRUE if the save succeeds and FALSE if it fails. Initialize the error pointer to NULL; when an error is returned, handle it and free it with g_error_free(). Documented failures can use either the GDK_PIXBUF_ERROR or G_FILE_ERROR domain. The filename uses the platform-native string encoding: the preferred OS encoding on Unix and UTF-8 on Windows. The format name is NUL-terminated UTF-8. See the GdkPixbuf save reference.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallChoose an output format supported at runtime
The variadic gdk_pixbuf_save() reference names JPEG, PNG, ICO, and BMP as possible default output formats, while noting that additional formats may be installed. The actual writable formats depend on the target installation, so do not assume that a format available on a development machine will also be available in deployment.
#1 Best Overall
Query the installed formats with gdk_pixbuf_get_formats() and check each with gdk_pixbuf_format_is_writable(). The format enumeration reference and writable-format check describe these runtime checks. The separate gdk_pixbuf_savev() reference lists JPEG, PNG, TIFF, ICO, and BMP; treat that as its documented list, not a guarantee that all savers are installed in every build. See gdk_pixbuf_savev().
Set options for the chosen format
In gdk_pixbuf_save(), pass save options as string key/value pairs and end the sequence with NULL. Options are format-sensitive; an option documented for one saver should not be presumed to work for another.
JPEG quality
JPEG accepts quality as integer text from 0 to 100. For example, "quality", "100" requests the top of the documented range; append NULL after the pair. The number is a saver setting, not a promise of a particular file size or visual result.
Free tools Windows power users keep installed
One-click scans. No signup required.
PNG compression and text
PNG accepts compression as integer text from 0 to 9. PNG text chunks use option keys shaped like tEXt::key; the ASCII key must be 1–79 characters, and its value is UTF-8.
Density and ICC profiles
JPEG and PNG document x-dpi and y-dpi density options in dots per inch. The icc-profile option takes the complete color profile encoded as base64; the documentation names PNG, JPEG, and TIFF support.
TIFF and ICO-specific options
- TIFF:
bits-per-sampleaccepts1or8. Its documentedcompressionvalues are1,2,5,7, and8, corresponding respectively to no compression, Huffman, LZW, JPEG, and DEFLATE. TIFF also accepts a base64icc-profile. - ICO:
depthaccepts16,24, or32. Supplying bothx_hotandy_hotmakes the ICO saver produce CUR output.
The full option details are in the save method reference.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Choose another destination or save flow
If the destination is not a filename, GdkPixbuf also provides buffer, callback, and GIO stream save APIs. A callback lets your application handle encoded output itself, including directing it to a memory buffer or socket. Stream methods are useful when the destination is a GOutputStream; asynchronous variants support an async flow. These interfaces are alternatives by destination and control flow, not documented performance rankings.
| Interface | Destination or flow | Version note |
|---|---|---|
gdk_pixbuf_save() |
Named file; variadic option pairs | See the save reference. |
gdk_pixbuf_savev() |
Named file; option names and values supplied as vectors | See the savev reference. |
| Callback save method | Caller-managed output, such as a buffer or socket | See the callback reference. |
save_to_stream |
Synchronous GIO stream | Available since GdkPixbuf 2.14, according to the class reference. |
| Async stream save | Asynchronous GIO stream | Available since 2.24, according to the class reference. |
| Streamv methods | Stream save with vector options | Available since 2.36, according to the class reference. |
The live GNOME API class reference displayed version 2.44.8 when consulted on 2026-10-04; that does not identify the version installed on your system. Check your installed library before relying on methods introduced in later versions.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




