# Gdk::Pixbuf Class Reference

Inheritance diagram for Gdk::Pixbuf:
[legend]
Collaboration diagram for Gdk::Pixbuf:
[legend]

List of all members.

## Public Types

typedef sigc::slot< void, const guint8* > | SlotDestroyData

## Public Member Functions

virtual | ~Pixbuf ()
GdkPixbuf* | gobj ()
| Provides access to the underlying C GObject.
const GdkPixbuf* | gobj () const
| Provides access to the underlying C GObject.
GdkPixbuf* | gobj_copy ()
| Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
Glib::RefPtr< Pixbuf > | copy () const
Colorspace | get_colorspace () const
int | get_n_channels () const
bool | get_has_alpha () const
int | get_bits_per_sample () const
guint8* | get_pixels () const
int | get_width () const
int | get_height () const
int | get_rowstride () const
void | fill (guint32 pixel)
void | save (const std::string& filename, const Glib::ustring&type)
| Saves pixbuf to a file in format type.
void | save (const std::string& filename, const Glib::ustring&type, const std::vector< Glib::ustring >& option_keys, const std::vector< Glib::ustring >& option_values)
| Saves pixbuf to a file in format type.
void | save_to_buffer (gchar*& buffer, gsize& buffer_size, const Glib::ustring&type="png")
void | save_to_buffer (gchar*& buffer, gsize& buffer_size, const Glib::ustring&type, const std::vector< Glib::ustring >& option_keys, const std::vector< Glib::ustring >& option_values)
Glib::RefPtr< Gdk::Pixbuf > | add_alpha (bool substitute_color, guint8 r, guint8 g, guint8 b) const
void | copy_area (int src_x, int src_y, int width, int height, const Glib::RefPtr< Gdk::Pixbuf >& dest_pixbuf, int dest_x, int dest_y) const
void | saturate_and_pixelate (const Glib::RefPtr< Gdk::Pixbuf >& dest, float saturation, bool pixelate) const
void | scale (const Glib::RefPtr< Gdk::Pixbuf >& dest, int dest_x, int dest_y, int dest_width, int dest_height, double offset_x, double offset_y, double scale_x, double scale_y, InterpType interp_type) const
void | composite (const Glib::RefPtr< Gdk::Pixbuf >& dest, int dest_x, int dest_y, int dest_width, int dest_height, double offset_x, double offset_y, double scale_x, double scale_y, InterpType interp_type, int overall_alpha) const
void | composite_color (const Glib::RefPtr< Gdk::Pixbuf >& dest, int dest_x, int dest_y, int dest_width, int dest_height, double offset_x, double offset_y, double scale_x, double scale_y, InterpType interp_type, int overall_alpha, int check_x, int check_y, int check_size, guint32 color1, guint32 color2) const
Glib::RefPtr< Gdk::Pixbuf > | scale_simple (int dest_width, int dest_height, InterpType interp_type) const
Glib::RefPtr< Gdk::Pixbuf > | composite_color_simple (int dest_width, int dest_height, InterpType interp_type, int overall_alpha, int check_size, guint32 color1, guint32 color2) const
Glib::RefPtr< Gdk::Pixbuf > | rotate_simple (PixbufRotation angle) const
Glib::RefPtr< Gdk::Pixbuf > | flip (bool horizontal=true) const
Glib::ustring | get_option (const Glib::ustring& key) const
Glib::RefPtr< Pixbuf > | apply_embedded_orientation ()

## Static Public Member Functions

static Glib::RefPtr< Pixbuf > | create (const Glib::RefPtr< Window >& src, int src_x, int src_y, int width, int height)
| Transfers image data from a #GdkWindow and converts it to an RGB(A) representation inside a Gdk::Pixbuf.
static Glib::RefPtr< Pixbuf > | create (const Cairo::RefPtr< Cairo::Surface >& src, int src_x, int src_y, int width, int height)
static Glib::RefPtr< Pixbuf > | create (Colorspace colorspace, bool has_alpha, int bits_per_sample, int width, int height)
static Glib::RefPtr< Pixbuf > | create_subpixbuf (const Glib::RefPtr< Pixbuf >& src_pixbuf, int src_x, int src_y, int width, int height)
static Glib::RefPtr< Pixbuf > | create_from_file (const std::string& filename)
| Creates a new pixbuf by loading an image from a file.
static Glib::RefPtr< Pixbuf > | create_from_file (const std::string& filename, int width, int height, bool preserve_aspect_ratio=true)
| Creates a new pixbuf by loading an image from a file.
static Glib::RefPtr< Pixbuf > | create_from_data (const guint8* data, Colorspace colorspace, bool has_alpha, int bits_per_sample, int width, int height, int rowstride)
| Creates a new Gdk::Pixbuf out of in-memory image data.
static Glib::RefPtr< Pixbuf > | create_from_data (const guint8* data, Colorspace colorspace, bool has_alpha, int bits_per_sample, int width, int height, int rowstride, const SlotDestroyData& destroy_slot)
| Creates a new Gdk::Pixbuf out of in-memory image data.
static Glib::RefPtr< Pixbuf > | create_from_xpm_data (const char* const* data)
static Glib::RefPtr< Pixbuf > | create_from_inline (int data_length, const guint8* data, bool copy_pixels=false)
| Create a Gdk::Pixbuf from a flat representation that is suitable for storing as inline data in a program.
static Glib::RefPtr< Pixbuf > | create_from_stream (const Glib::RefPtr< Gio::InputStream >& stream, const Glib::RefPtr< Gio::Cancellable >& cancelable)
static Glib::RefPtr< Pixbuf > | create_from_stream (const Glib::RefPtr< Gio::InputStream >& stream)
static Glib::RefPtr< Pixbuf > | create_from_stream_at_scale (const Glib::RefPtr< Gio::InputStream >& stream, int width, int height, bool preserve_aspect_ratio, const Glib::RefPtr< Gio::Cancellable >& cancelable)
static Glib::RefPtr< Pixbuf > | create_from_stream_at_scale (const Glib::RefPtr< Gio::InputStream >& stream, int width, int height, bool preserve_aspect_ratio)
static std::vector< PixbufFormat > | get_formats ()
| Obtains the available information about the image formats supported by GdkPixbuf.

## Protected Member Functions

| Pixbuf (const Glib::RefPtr< Window >& src, int src_x, int src_y, int width, int height)
| Transfers image data from a #GdkWindow and converts it to an RGB(A) representation inside a Gdk::Pixbuf.
| Pixbuf (const Cairo::RefPtr< Cairo::Surface >& src, int src_x, int src_y, int width, int height)

## Related Functions

(Note that these are not member functions.)
Glib::RefPtr< Gdk::Pixbuf > | wrap (GdkPixbuf* object, bool take_copy=false)
| A Glib::wrap() method for this object.

## Member Typedef Documentation

typedef sigc::slot<void, const guint8*> Gdk::Pixbuf::SlotDestroyData

## Constructor & Destructor Documentation

virtual Gdk::Pixbuf::~Pixbuf | ( |  | ) | `[virtual]`

Gdk::Pixbuf::Pixbuf | ( | const Glib::RefPtr< Window >& | src,
|  | int | src_x,
|  | int | src_y,
|  | int | width,
|  | int | height
| ) |  | `[protected]`

Transfers image data from a #GdkWindow and converts it to an RGB(A) representation inside a Gdk::Pixbuf.

In other words, copies image data from a server-side drawable to a client-side RGB(A) buffer. This allows you to efficiently read individual pixels on the client side.

This function will create an RGB pixbuf with 8 bits per channel with the same size specified by the width and height arguments. The pixbuf will contain an alpha channel if the window contains one.

If the window is off the screen, then there is no image data in the obscured/offscreen regions to be placed in the pixbuf. The contents of portions of the pixbuf corresponding to the offscreen region are undefined.

If the window you're obtaining data from is partially obscured by other windows, then the contents of the pixbuf areas corresponding to the obscured regions are undefined.

If the window is not mapped (typically because it's iconified/minimized or not on the current workspace), then an invalid object will be returned.

If memory can't be allocated for the return value, an invalid object will be returned instead.

Parameters:

  src | Source window.
  src_x | Source X coordinate within the window.
  src_y | Source Y coordinate within the window.
  width | Width in pixels of region to get.
  height | Height in pixels of region to get.

Since gtkmm 2.12:

Gdk::Pixbuf::Pixbuf | ( | const Cairo::RefPtr< Cairo::Surface > & | src,
|  | int | src_x,
|  | int | src_y,
|  | int | width,
|  | int | height
| ) |  | `[protected]`

Since gtkmm 2.30:

## Member Function Documentation

Glib::RefPtr<Gdk::Pixbuf> Gdk::Pixbuf::add_alpha | ( | bool | substitute_color,
|  | guint8 | r,
|  | guint8 | g,
|  | guint8 | b
| ) |  | const

Glib::RefPtr<Pixbuf> Gdk::Pixbuf::apply_embedded_orientation | ( |  | ) |

void Gdk::Pixbuf::composite | ( | const Glib::RefPtr< Gdk::Pixbuf >& | dest,
|  | int | dest_x,
|  | int | dest_y,
|  | int | dest_width,
|  | int | dest_height,
|  | double | offset_x,
|  | double | offset_y,
|  | double | scale_x,
|  | double | scale_y,
|  | InterpType | interp_type,
|  | int | overall_alpha
| ) |  | const

void Gdk::Pixbuf::composite_color | ( | const Glib::RefPtr< Gdk::Pixbuf >& | dest,
|  | int | dest_x,
|  | int | dest_y,
|  | int | dest_width,
|  | int | dest_height,
|  | double | offset_x,
|  | double | offset_y,
|  | double | scale_x,
|  | double | scale_y,
|  | InterpType | interp_type,
|  | int | overall_alpha,
|  | int | check_x,
|  | int | check_y,
|  | int | check_size,
|  | guint32 | color1,
|  | guint32 | color2
| ) |  | const

Glib::RefPtr<Gdk::Pixbuf> Gdk::Pixbuf::composite_color_simple | ( | int | dest_width,
|  | int | dest_height,
|  | InterpType | interp_type,
|  | int | overall_alpha,
|  | int | check_size,
|  | guint32 | color1,
|  | guint32 | color2
| ) |  | const

Glib::RefPtr<Pixbuf> Gdk::Pixbuf::copy | ( |  | ) | const

void Gdk::Pixbuf::copy_area | ( | int | src_x,
|  | int | src_y,
|  | int | width,
|  | int | height,
|  | const Glib::RefPtr< Gdk::Pixbuf >& | dest_pixbuf,
|  | int | dest_x,
|  | int | dest_y
| ) |  | const

static Glib::RefPtr<Pixbuf> Gdk::Pixbuf::create | ( | const Cairo::RefPtr< Cairo::Surface > & | src,
|  | int | src_x,
|  | int | src_y,
|  | int | width,
|  | int | height
| ) |  | `[static]`

Since gtkmm 2.30:

static Glib::RefPtr<Pixbuf> Gdk::Pixbuf::create | ( | const Glib::RefPtr< Window >& | src,
|  | int | src_x,
|  | int | src_y,
|  | int | width,
|  | int | height
| ) |  | `[static]`

Transfers image data from a #GdkWindow and converts it to an RGB(A) representation inside a Gdk::Pixbuf.

In other words, copies image data from a server-side drawable to a client-side RGB(A) buffer. This allows you to efficiently read individual pixels on the client side.

This function will create an RGB pixbuf with 8 bits per channel with the same size specified by the width and height arguments. The pixbuf will contain an alpha channel if the window contains one.

If the window is off the screen, then there is no image data in the obscured/offscreen regions to be placed in the pixbuf. The contents of portions of the pixbuf corresponding to the offscreen region are undefined.

If the window you're obtaining data from is partially obscured by other windows, then the contents of the pixbuf areas corresponding to the obscured regions are undefined.

If the window is not mapped (typically because it's iconified/minimized or not on the current workspace), then an invalid object will be returned.

If memory can't be allocated for the return value, an invalid object will be returned instead.

Parameters:

  src | Source window.
  src_x | Source X coordinate within the window.
  src_y | Source Y coordinate within the window.
  width | Width in pixels of region to get.
  height | Height in pixels of region to get.

Since gtkmm 2.12:

static Glib::RefPtr<Pixbuf> Gdk::Pixbuf::create | ( | Colorspace | colorspace,
|  | bool | has_alpha,
|  | int | bits_per_sample,
|  | int | width,
|  | int | height
| ) |  | `[static]`

static Glib::RefPtr<Pixbuf> Gdk::Pixbuf::create_from_data | ( | const guint8 * | data,
|  | Colorspace | colorspace,
|  | bool | has_alpha,
|  | int | bits_per_sample,
|  | int | width,
|  | int | height,
|  | int | rowstride
| ) |  | `[static]`

Creates a new Gdk::Pixbuf out of in-memory image data.

Currently only RGB images with 8 bits per sample are supported.

Parameters:

  data | Image data in 8-bit/sample packed format.
  colorspace | Colorspace for the image data.
  has_alpha | Whether the data has an opacity channel.
  bits_per_sample | Number of bits per sample.
  width | Width of the image in pixels.
  height | Height of the image in pixels.
  rowstride | Distance in bytes between rows.

Returns:
  A newly-created Gdk::Pixbuf object.

static Glib::RefPtr<Pixbuf> Gdk::Pixbuf::create_from_data | ( | const guint8 * | data,
|  | Colorspace | colorspace,
|  | bool | has_alpha,
|  | int | bits_per_sample,
|  | int | width,
|  | int | height,
|  | int | rowstride,
|  | const SlotDestroyData & | destroy_slot
| ) |  | `[static]`

Creates a new Gdk::Pixbuf out of in-memory image data.

Currently only RGB images with 8 bits per sample are supported.

Parameters:

  data | Image data in 8-bit/sample packed format.
  colorspace | Colorspace for the image data.
  has_alpha | Whether the data has an opacity channel.
  bits_per_sample | Number of bits per sample.
  width | Width of the image in pixels.
  height | Height of the image in pixels.
  rowstride | Distance in bytes between rows.
  destroy_slot | Slot used to free the data when the pixbuf's reference count drops to zero.

Returns:
  A newly-created Gdk::Pixbuf object.

static Glib::RefPtr<Pixbuf> Gdk::Pixbuf::create_from_file | ( | const std::string & | filename | ) | `[static]`

Creates a new pixbuf by loading an image from a file.

The file format is detected automatically.

Parameters:

  filename | The path to the pixbuf file.

Exceptions:

  Glib::FileError |
  Gdk::PixbufError |

static Glib::RefPtr<Pixbuf> Gdk::Pixbuf::create_from_file | ( | const std::string & | filename,
|  | int | width,
|  | int | height,
|  | bool | preserve_aspect_ratio = `true`
| ) |  | `[static]`

Creates a new pixbuf by loading an image from a file.

The file format is detected automatically. The image will be scaled to fit in the requested size.

Parameters:

  filename | The path to the pixbuf file.
  width | The desired width
  height | The desired height
  preserve_aspect_ratio,: | Whether the image's aspect ratio will be preserved when scaling.

Exceptions:

  Glib::FileError |
  Gdk::PixbufError |

static Glib::RefPtr<Pixbuf> Gdk::Pixbuf::create_from_inline | ( | int | data_length,
|  | const guint8 * | data,
|  | bool | copy_pixels = `false`
| ) |  | `[static]`

Create a Gdk::Pixbuf from a flat representation that is suitable for storing as inline data in a program.

This is useful if you want to ship a program with images, but don't want to depend on any external files.

GTK+ ships with a program called `gdk-pixbuf-csource` which allows for conversion of GdkPixbufs into such a inline representation. In almost all cases, you should pass the `--raw` flag to `gdk-pixbuf-csource`. A sample invocation would be:

`gdk-pixbuf-csource --raw --name=myimage_inline myimage.png`

For the typical case where the inline pixbuf is read-only static data, you don't need to copy the pixel data unless you intend to write to it, so you can pass `false` for copy_pixels. (If you pass `--rle` to `gdk-pixbuf-csource`, a copy will be made even if copy_pixels is `false`, so using this option is generally a bad idea.)

If you create a pixbuf from const inline data compiled into your program, it's probably safe to ignore errors, since things will always succeed. For non-const inline data, you could get out of memory. For untrusted inline data located at runtime, you could have corrupt inline data in addition.

Parameters:

  data_length | Length in bytes of the data argument.
  data | Byte data containing a serialized GdkPixdata structure.
  copy_pixels | Whether to copy the pixel data, or use direct pointers to data for the resulting pixbuf.

Exceptions:

  Gdk::PixbufError |

static Glib::RefPtr<Pixbuf> Gdk::Pixbuf::create_from_stream | ( | const Glib::RefPtr< Gio::InputStream > & | stream | ) | `[static]`

static Glib::RefPtr<Pixbuf> Gdk::Pixbuf::create_from_stream | ( | const Glib::RefPtr< Gio::InputStream > & | stream,
|  | const Glib::RefPtr< Gio::Cancellable > & | cancelable
| ) |  | `[static]`

static Glib::RefPtr<Pixbuf> Gdk::Pixbuf::create_from_stream_at_scale | ( | const Glib::RefPtr< Gio::InputStream > & | stream,
|  | int | width,
|  | int | height,
|  | bool | preserve_aspect_ratio,
|  | const Glib::RefPtr< Gio::Cancellable > & | cancelable
| ) |  | `[static]`

static Glib::RefPtr<Pixbuf> Gdk::Pixbuf::create_from_stream_at_scale | ( | const Glib::RefPtr< Gio::InputStream > & | stream,
|  | int | width,
|  | int | height,
|  | bool | preserve_aspect_ratio
| ) |  | `[static]`

static Glib::RefPtr<Pixbuf> Gdk::Pixbuf::create_from_xpm_data | ( | const char *const * | data | ) | `[static]`

static Glib::RefPtr<Pixbuf> Gdk::Pixbuf::create_subpixbuf | ( | const Glib::RefPtr< Pixbuf >& | src_pixbuf,
|  | int | src_x,
|  | int | src_y,
|  | int | width,
|  | int | height
| ) |  | `[static]`

Parameters:

  src_pixbuf | A Gdk::Pixbuf.
  src_x | X coord in src_pixbuf.
  src_y | Y coord in src_pixbuf.
  width | Width of region in src_pixbuf.
  height | Height of region in src_pixbuf.

void Gdk::Pixbuf::fill | ( | guint32 | pixel | ) |

Glib::RefPtr<Gdk::Pixbuf> Gdk::Pixbuf::flip | ( | bool | horizontal = `true` | ) | const

int Gdk::Pixbuf::get_bits_per_sample | ( |  | ) | const

Colorspace Gdk::Pixbuf::get_colorspace | ( |  | ) | const

static std::vector<PixbufFormat> Gdk::Pixbuf::get_formats | ( |  | ) | `[static]`

Obtains the available information about the image formats supported by GdkPixbuf.

Returns:
  A list of PixbufFormats describing the supported image formats.

bool Gdk::Pixbuf::get_has_alpha | ( |  | ) | const

int Gdk::Pixbuf::get_height | ( |  | ) | const

int Gdk::Pixbuf::get_n_channels | ( |  | ) | const

Glib::ustring Gdk::Pixbuf::get_option | ( | const Glib::ustring & | key | ) | const

guint8* Gdk::Pixbuf::get_pixels | ( |  | ) | const

int Gdk::Pixbuf::get_rowstride | ( |  | ) | const

int Gdk::Pixbuf::get_width | ( |  | ) | const

const GdkPixbuf* Gdk::Pixbuf::gobj | ( |  | ) | const`[inline]`

Provides access to the underlying C GObject.

Reimplemented from Gio::Icon.

GdkPixbuf* Gdk::Pixbuf::gobj | ( |  | ) | `[inline]`

Provides access to the underlying C GObject.

Reimplemented from Gio::Icon.

GdkPixbuf* Gdk::Pixbuf::gobj_copy | ( |  | ) |

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

Glib::RefPtr<Gdk::Pixbuf> Gdk::Pixbuf::rotate_simple | ( | PixbufRotation | angle | ) | const

void Gdk::Pixbuf::saturate_and_pixelate | ( | const Glib::RefPtr< Gdk::Pixbuf >& | dest,
|  | float | saturation,
|  | bool | pixelate
| ) |  | const

void Gdk::Pixbuf::save | ( | const std::string & | filename,
|  | const Glib::ustring & | type,
|  | const std::vector< Glib::ustring > & | option_keys,
|  | const std::vector< Glib::ustring > & | option_values
| ) |  |

Saves pixbuf to a file in format type.

By default, "jpeg", "png", "ico" and "bmp" are possible file formats to save in, but more formats may be installed. TThe list of all writable formats can be determined by using get_formats() with Gdk::PixbufFormat::is_writable().

The option_keys and , if not empty, should contain pairs of strings that modify the save parameters. For example, "quality", "100".

Currently only a few parameters exist. JPEG images can be saved with a "quality" parameter; its value should be in the range [0,100]. Text chunks can be attached to PNG images by specifying parameters of the form "tEXt::key", where key is an ASCII string of length 1-79. The values are UTF-8 encoded strings. ICO images can be saved in depth 16, 24, or 32, by using the "depth" parameter. When the ICO saver is given "x_hot" and "y_hot" parameters, it produces a CUR instead of an ICO.

Parameters:

  filename | The path of the file to be created.
  type | The file type.
  option_keys |
  option_values |

Exceptions:

  Glib::FileError |
  Gdk::PixbufError |

void Gdk::Pixbuf::save | ( | const std::string & | filename,
|  | const Glib::ustring & | type
| ) |  |

Saves pixbuf to a file in format type.

By default, "jpeg", "png", "ico" and "bmp" are possible file formats to save in, but more formats may be installed. The list of all writable formats can be determined by using get_formats() with is_writable().

Parameters:

  filename | The path of the file to be created.
  type | The file type.

Exceptions:

  Glib::FileError |
  Gdk::PixbufError |

void Gdk::Pixbuf::save_to_buffer | ( | gchar *& | buffer,
|  | gsize & | buffer_size,
|  | const Glib::ustring & | type,
|  | const std::vector< Glib::ustring > & | option_keys,
|  | const std::vector< Glib::ustring > & | option_values
| ) |  |

void Gdk::Pixbuf::save_to_buffer | ( | gchar *& | buffer,
|  | gsize & | buffer_size,
|  | const Glib::ustring & | type = `"png"`
| ) |  |

void Gdk::Pixbuf::scale | ( | const Glib::RefPtr< Gdk::Pixbuf >& | dest,
|  | int | dest_x,
|  | int | dest_y,
|  | int | dest_width,
|  | int | dest_height,
|  | double | offset_x,
|  | double | offset_y,
|  | double | scale_x,
|  | double | scale_y,
|  | InterpType | interp_type
| ) |  | const

Glib::RefPtr<Gdk::Pixbuf> Gdk::Pixbuf::scale_simple | ( | int | dest_width,
|  | int | dest_height,
|  | InterpType | interp_type
| ) |  | const

## Friends And Related Function Documentation

Glib::RefPtr< Gdk::Pixbuf > wrap | ( | GdkPixbuf * | object,
|  | bool | take_copy = `false`
| ) |  | `[related]`

A Glib::wrap() method for this object.

Parameters:

  object | The C instance.
  take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref.

Returns:
  A C++ instance that wraps this C instance.

The documentation for this class was generated from the following file:

- gdkmm/pixbuf.h