October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Save a GdkPixbuf to a File in C

A practical guide to saving GdkPixbuf images in C, checking errors and runtime format support, setting format-specific options, and choosing file, buffer, callback, or stream output.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose 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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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-sample accepts 1 or 8. Its documented compression values are 1, 2, 5, 7, and 8, corresponding respectively to no compression, Huffman, LZW, JPEG, and DEFLATE. TIFF also accepts a base64 icc-profile.
  • ICO: depth accepts 16, 24, or 32. Supplying both x_hot and y_hot makes 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.Support on Ko-Fi

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.