# Gdk::Pixbuf Class Reference

Inherits Glib::Object.

Collaboration diagram for Gdk::Pixbuf:

[legend]

List of all members.

## Public Types

typedef sigc::slot< void, const guint8* > | SlotDestroyData
typedef Glib::SListHandle < Glib::RefPtr< PixbufFormat > , PixbufFormatTraits > | SListHandle_PixbufFormat

## 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
| Creates a new Gdk::Pixbuf with a copy of the information in the specified pixbuf.
Colorspace | get_colorspace () const
| Queries the color space of a pixbuf.
int | get_n_channels () const
bool | get_has_alpha () const
| Queries whether a pixbuf has an alpha channel (opacity information).
int | get_bits_per_sample () const
guint8* | get_pixels () const
| Queries a pointer to the pixel data of a pixbuf.
int | get_width () const
int | get_height () const
| Queries the height of a pixbuf.
int | get_rowstride () const
void | fill (guint32 pixel)
| Clears a pixbuf to the given RGBA value, converting the RGBA value into the pixbuf's pixel format.
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 Glib::StringArrayHandle& option_keys, const Glib::StringArrayHandle& 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 Glib::StringArrayHandle& option_keys, const Glib::StringArrayHandle& 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
| Copies a rectangular area from src_pixbuf to dest_pixbuf.
void | saturate_and_pixelate (const Glib::RefPtr< Gdk::Pixbuf >& dest, float saturation, bool pixelate) const
| Modifies saturation and optionally pixelates src, placing the result in dest.
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
| Creates a transformation of the source image src by scaling by scale_x and scale_y then translating by offset_x and offset_y, then renders the rectangle ( dest_x, dest_y, dest_width, dest_height) of the resulting image onto the destination image replacing the previous contents.
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
| Creates a transformation of the source image src by scaling by scale_x and scale_y then translating by offset_x and offset_y, then composites the rectangle ( dest_x , dest_y, dest_width, dest_height) of the resulting image with a checkboard of the colors color1 and color2 and renders it onto the destination image.
Glib::RefPtr< Gdk::Pixbuf > | scale_simple (int dest_width, int dest_height, InterpType interp_type) const
| Create a new Gdk::Pixbuf containing a copy of src scaled to dest_width x dest_height.
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
| Flips a pixbuf horizontally or vertically and returns the result in a new pixbuf.
void | render_threshold_alpha (const Glib::RefPtr< Gdk::Bitmap >& bitmap, int src_x, int src_y, int dest_x, int dest_y, int width, int height, int alpha_threshold)
| Takes the opacity values in a rectangular portion of a pixbuf and thresholds them to produce a bi-level alpha mask that can be used as a clipping mask for a drawable.
void | render_to_drawable (const Glib::RefPtr< Drawable >& drawable, const Glib::RefPtr< Gdk::GC >& gc, int src_x, int src_y, int dest_x, int dest_y, int width, int height, RgbDither dither, int x_dither, int y_dither)
void | render_to_drawable_alpha (const Glib::RefPtr< Drawable >& drawable, int src_x, int src_y, int dest_x, int dest_y, int width, int height, PixbufAlphaMode alpha_mode, int alpha_threshold, RgbDither dither, int x_dither, int y_dither)
void | render_pixmap_and_mask_for_colormap (const Glib::RefPtr< Colormap >& colormap, Glib::RefPtr< Pixmap >& pixmap_return, Glib::RefPtr< Bitmap >& mask_return, int alpha_threshold)
void | render_pixmap_and_mask (Glib::RefPtr< Pixmap >& pixmap_return, Glib::RefPtr< Bitmap >& mask_return, int alpha_threshold)
Glib::ustring | get_option (const Glib::ustring& key) const

## Static Public Member Functions

static Glib::RefPtr< Gdk::Pixbuf > | create (const Glib::RefPtr< Drawable >& src, const Glib::RefPtr< Colormap >& cmap, int src_x, int src_y, int dest_x, int dest_y, int width, int height)
static Glib::RefPtr< Gdk::Pixbuf > | create (const Glib::RefPtr< Image >& src, const Glib::RefPtr< Colormap >& cmap, int src_x, int src_y, int dest_x, int dest_y, int width, int height)
static Glib::RefPtr< Pixbuf > | create (const Glib::RefPtr< Drawable >& src, const Glib::RefPtr< Colormap >& cmap, int src_x, int src_y, int width, int height)
| Creates a pixbuf object from a drawable.
static Glib::RefPtr< Pixbuf > | create (const Glib::RefPtr< Drawable >& src, int src_x, int src_y, int width, int height)
| Creates a pixbuf object from a drawable, using the colormap from the drawable.
static Glib::RefPtr< Pixbuf > | create (const Glib::RefPtr< Image >& src, const Glib::RefPtr< Colormap >& cmap, int src_x, int src_y, int width, int height)
| Creates a pixbuf object from an image.
static Glib::RefPtr< Pixbuf > | create (const Glib::RefPtr< Image >& src, int src_x, int src_y, int width, int height)
| Creates a pixbuf object from an image, using the colormap from the image.
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)
| Creates a new pixbuf by parsing XPM data in memory.
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)
| Creates a new pixbuf by loading an image from an input stream.
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)
| Creates a new pixbuf by loading an image from an input stream.
static Glib::RefPtr< Pixbuf > | create_from_stream_at_scale (const Glib::RefPtr< Gio::InputStream >& stream, int width, int height, bool preserve_aspect_ratio)
static SListHandle_PixbufFormat | get_formats ()

## Protected Member Functions

| Pixbuf (const Glib::RefPtr< Drawable >& src, const Glib::RefPtr< Colormap >& cmap, int src_x, int src_y, int width, int height)
| Creates a pixbuf object from a drawable.
| Pixbuf (const Glib::RefPtr< Drawable >& src, int src_x, int src_y, int width, int height)
| Creates a pixbuf object from a drawable, using the colormap from the drawable.
| Pixbuf (const Glib::RefPtr< Drawable >& src, const Glib::RefPtr< Colormap >& cmap, int src_x, int src_y, int dest_x, int dest_y, int width, int height)
| Pixbuf (const Glib::RefPtr< Image >& src, const Glib::RefPtr< Colormap >& cmap, int src_x, int src_y, int width, int height)
| Creates a pixbuf object from an image.
| Pixbuf (const Glib::RefPtr< Image >& src, int src_x, int src_y, int width, int height)
| Creates a pixbuf object from an image, using the colormap from the image.
| Pixbuf (const Glib::RefPtr< Image >& src, const Glib::RefPtr< Colormap >& cmap, int src_x, int src_y, int dest_x, int dest_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 Glib::SListHandle< Glib::RefPtr<PixbufFormat>, PixbufFormatTraits > Gdk::Pixbuf::SListHandle_PixbufFormat

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

## Constructor & Destructor Documentation

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

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

Creates a pixbuf object from a drawable.

Transfers image data from a Drawable and converts it to an RGB(A) representation inside a 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.

If the drawable has no colormap (See Gdk::Drawable::get_colormap()), then a suitable colormap must be specified. Otherwise, you may use the constructor that takes no colormap argument. Typically a Gdk::Window or a pixmap created by passing a Gdk:Window to the Gdk::Pixbuf constructor will already have a colormap associated with it. If the drawable is a bitmap (1 bit per pixel pixmap), then a colormap is not required; pixels with a value of 1 are assumed to be white, and pixels with a value of 0 are assumed to be black. For taking screenshots, Gdk::Colormap::get_system() returns the correct colormap to use.

This will create an RGB pixbuf with 8 bits per channel and no alpha, with the same size specified by the width and height arguments.

If the specified drawable is a pixmap, then the requested source rectangle must be completely contained within the pixmap, otherwise the constructor will fail. For pixmaps only (not for windows) passing -1 for width or height is allowed to mean the full width or height of the pixmap.

If the specified drawable is a window, and 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.

See alo Gdk::Drawable::get_image().

Parameters:

  | src | Source drawable.
  | cmap,: | A colormap.
  | src_x | Source X coordinate within drawable.
  | src_y | Source Y coordinate within drawable.
  | width | Width in pixels of region to get.
  | height | Height in pixels of region to get.

Since gtkmm 2.12:

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

Creates a pixbuf object from a drawable, using the colormap from the drawable.

Parameters:

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

Since gtkmm 2.12:

Gdk::Pixbuf::Pixbuf | ( | const Glib::RefPtr< Drawable >& | src,
|  | const Glib::RefPtr< Colormap >& | cmap,
|  | int | src_x,
|  | int | src_y,
|  | int | dest_x,
|  | int | dest_y,
|  | int | width,
|  | int | height |
| ) |  |  | `[protected]`

Deprecated:
  Use the constructor without dest_x and dest_y parameters.

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

Creates a pixbuf object from an image.

Parameters:

  | src | Source Image.
  | cmap | A colormap.
  | src_x | Source X coordinate within the image.
  | src_y | Source Y coordinate within the image.
  | width | Width in pixels of region to get.
  | height | Height in pixels of region to get.

Since gtkmm 2.12:

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

Creates a pixbuf object from an image, using the colormap from the image.

Parameters:

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

Gdk::Pixbuf::Pixbuf | ( | const Glib::RefPtr< Image >& | src,
|  | const Glib::RefPtr< Colormap >& | cmap,
|  | int | src_x,
|  | int | src_y,
|  | int | dest_x,
|  | int | dest_y,
|  | int | width,
|  | int | height |
| ) |  |  | `[protected]`

Deprecated:
  Use the constructors without dest_x and dest_y parameters.

## Member Function Documentation

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

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

Creates a transformation of the source image src by scaling by scale_x and scale_y then translating by offset_x and offset_y, then composites the rectangle ( dest_x , dest_y, dest_width, dest_height) of the resulting image with a checkboard of the colors color1 and color2 and renders it onto the destination image.

See composite_color_simple() for a simpler variant of this function suitable for many tasks.

Parameters:

  | dest | The Gdk::Pixbuf into which to render the results.
  | dest_x | The left coordinate for region to render.
  | dest_y | The top coordinate for region to render.
  | dest_width | The width of the region to render.
  | dest_height | The height of the region to render.
  | offset_x | The offset in the X direction (currently rounded to an integer).
  | offset_y | The offset in the Y direction (currently rounded to an integer).
  | scale_x | The scale factor in the X direction.
  | scale_y | The scale factor in the Y direction.
  | interp_type | The interpolation type for the transformation.
  | overall_alpha | Overall alpha for source image (0..255).
  | check_x | The X offset for the checkboard (origin of checkboard is at - check_x, - check_y).
  | check_y | The Y offset for the checkboard.
  | check_size | The size of checks in the checkboard (must be a power of two).
  | color1 | The color of check at upper left.
  | color2 | The color of the other check.

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

Creates a new Gdk::Pixbuf with a copy of the information in the specified pixbuf.

Returns:
  A newly-created pixbuf with a reference count of 1, or `0` if not enough memory could be allocated.

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

Copies a rectangular area from src_pixbuf to dest_pixbuf.

Conversion of pixbuf formats is done automatically.

If the source rectangle overlaps the destination rectangle on the same pixbuf, it will be overwritten during the copy operation. Therefore, you can not use this function to scroll a pixbuf.

Parameters:

  | src_x | Source X coordinate within src_pixbuf.
  | src_y | Source Y coordinate within src_pixbuf.
  | width | Width of the area to copy.
  | height | Height of the area to copy.
  | dest_pixbuf | Destination pixbuf.
  | dest_x | X coordinate within dest_pixbuf.
  | dest_y | Y coordinate within dest_pixbuf.

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 | ( | const Glib::RefPtr< Image >& | src,
|  | int | src_x,
|  | int | src_y,
|  | int | width,
|  | int | height |
| ) |  |  | `[static]`

Creates a pixbuf object from an image, using the colormap from the image.

Parameters:

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

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

Creates a pixbuf object from an image.

Parameters:

  | src | Source Image.
  | cmap | A colormap.
  | src_x | Source X coordinate within the image.
  | src_y | Source Y coordinate within the image.
  | 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 | ( | const Glib::RefPtr< Drawable >& | src,
|  | int | src_x,
|  | int | src_y,
|  | int | width,
|  | int | height |
| ) |  |  | `[static]`

Creates a pixbuf object from a drawable, using the colormap from the drawable.

Parameters:

  | src | Source drawable.
  | src_x | Source X coordinate within drawable.
  | src_y | Source Y coordinate within drawable.
  | 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 | ( | const Glib::RefPtr< Drawable >& | src,
|  | const Glib::RefPtr< Colormap >& | cmap,
|  | int | src_x,
|  | int | src_y,
|  | int | width,
|  | int | height |
| ) |  |  | `[static]`

Creates a pixbuf object from a drawable.

Transfers image data from a Drawable and converts it to an RGB(A) representation inside a 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.

If the drawable has no colormap (See Gdk::Drawable::get_colormap()), then a suitable colormap must be specified. Otherwise, you may use the constructor that takes no colormap argument. Typically a Gdk::Window or a pixmap created by passing a Gdk:Window to the Gdk::Pixbuf constructor will already have a colormap associated with it. If the drawable is a bitmap (1 bit per pixel pixmap), then a colormap is not required; pixels with a value of 1 are assumed to be white, and pixels with a value of 0 are assumed to be black. For taking screenshots, Gdk::Colormap::get_system() returns the correct colormap to use.

This will create an RGB pixbuf with 8 bits per channel and no alpha, with the same size specified by the width and height arguments.

If the specified drawable is a pixmap, then the requested source rectangle must be completely contained within the pixmap, otherwise the constructor will fail. For pixmaps only (not for windows) passing -1 for width or height is allowed to mean the full width or height of the pixmap.

If the specified drawable is a window, and 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.

See alo Gdk::Drawable::get_image().

Parameters:

  | src | Source drawable.
  | cmap,: | A colormap.
  | src_x | Source X coordinate within drawable.
  | src_y | Source Y coordinate within drawable.
  | width | Width in pixels of region to get.
  | height | Height in pixels of region to get.

Since gtkmm 2.12:

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

Deprecated:
  Use the create() methods that that don't have the unused dest_x and dest_y parameters.

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

Deprecated:
  Use the create() methods that don't have the unused dest_x and dest_y parameters.

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_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_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_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 | Creates a new pixbuf by loading an image from a file. The file format is detected automatically. If `0` is returned, then error will be set. Possible errors are in the Gdk::PIXBUF_ERROR and FILE_ERROR domains.

Parameters:

  | filename | Name of file to load, in the GLib file name encoding.

Returns:
  A newly-created pixbuf with a reference count of 1, or `0` if any of several error conditions occurred: the file could not be opened, there was no loader for the file's format, there was not enough memory to allocate the image buffer, or the image file contained invalid data.

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 | 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 <command>gdk-pixbuf-csource</command> which allows for conversion of Gdk::Pixbufs into such a inline representation. In almost all cases, you should pass the <option>--raw</option> flag to <command>gdk-pixbuf-csource</command>. A sample invocation would be:

<informalexample><programlisting> gdk-pixbuf-csource --raw --name=myimage_inline myimage.png </programlisting></informalexample>

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 <option>--rle</option> to <command>gdk-pixbuf-csource</command>, 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 and disable length checks, since things will always succeed: <informalexample><programlisting> pixbuf = gdk_pixbuf_new_from_inline (-1, myimage_inline, `false`, `0`); </programlisting></informalexample>

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 or -1 to disable length checks.
  | data | Byte data containing a serialized Gdk::Pixdata structure.
  | copy_pixels | Whether to copy the pixel data, or use direct pointers data for the resulting pixbuf.

Returns:
  A newly-created Gdk::Pixbuf structure with a reference, count of 1, or `0` if an error occurred.

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]`

Creates a new pixbuf by loading an image from an input stream.

The file format is detected automatically. If `0` is returned, then error will be set. The cancellable can be used to abort the operation from another thread. If the operation was cancelled, the error Gio::ERROR_CANCELLED will be returned. Other possible errors are in the Gdk::PIXBUF_ERROR and IO_ERROR domains.

The stream is not closed.

Parameters:

  | stream | A InputStream to load the pixbuf from.
  | cancellable | Optional Cancellable object, `0` to ignore.

Returns:
  A newly-created pixbuf, or `0` if any of several error conditions occurred: the file could not be opened, the image format is not supported, there was not enough memory to allocate the image buffer, the stream contained invalid data, or the operation was cancelled.

Since gtkmm 2.14:

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_stream_at_scale | ( | const Glib::RefPtr< Gio::InputStream > & | stream,
|  | int | width,
|  | int | height,
|  | bool | preserve_aspect_ratio,
|  | const Glib::RefPtr< Gio::Cancellable > & | cancelable |
| ) |  |  | `[static]`

Creates a new pixbuf by loading an image from an input stream.

The file format is detected automatically. If `0` is returned, then error will be set. The cancellable can be used to abort the operation from another thread. If the operation was cancelled, the error Gio::ERROR_CANCELLED will be returned. Other possible errors are in the Gdk::PIXBUF_ERROR and IO_ERROR domains.

The image will be scaled to fit in the requested size, optionally preserving the image's aspect ratio. When preserving the aspect ratio, a width of -1 will cause the image to be scaled to the exact given height, and a height of -1 will cause the image to be scaled to the exact given width. When not preserving aspect ratio, a width or height of -1 means to not scale the image at all in that dimension.

The stream is not closed.

Parameters:

  | stream | A InputStream to load the pixbuf from.
  | width | The width the image should have or -1 to not constrain the width.
  | height | The height the image should have or -1 to not constrain the height.
  | preserve_aspect_ratio | `true` to preserve the image's aspect ratio.
  | cancellable | Optional Cancellable object, `0` to ignore.

Returns:
  A newly-created pixbuf, or `0` if any of several error conditions occurred: the file could not be opened, the image format is not supported, there was not enough memory to allocate the image buffer, the stream contained invalid data, or the operation was cancelled.

Since gtkmm 2.14:

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

Creates a new pixbuf by parsing XPM data in memory.

This data is commonly the result of including an XPM file into a program's C source.

Parameters:

  | data | Pointer to inline XPM data.

Returns:
  A newly-created pixbuf with a reference count of 1.

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]`

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

Clears a pixbuf to the given RGBA value, converting the RGBA value into the pixbuf's pixel format.

The alpha will be ignored if the pixbuf doesn't have an alpha channel.

Parameters:

  | pixel | RGBA pixel to clear to (0xffffffff is opaque white, 0x00000000 transparent black).

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

Flips a pixbuf horizontally or vertically and returns the result in a new pixbuf.

Parameters:

  | horizontal | `true` to flip horizontally, `false` to flip vertically.

Returns:
  The new Gdk::Pixbuf, or `0` if not enough memory could be allocated for it.

Since gtkmm 2.6:

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

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

Queries the color space of a pixbuf.

Returns:
  Color space.

static SListHandle_PixbufFormat Gdk::Pixbuf::get_formats | ( |  | ) | `[static]`

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

Queries whether a pixbuf has an alpha channel (opacity information).

Returns:
  `true` if it has an alpha channel, `false` otherwise.

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

Queries the height of a pixbuf.

Returns:
  Height in pixels.

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

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

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

Queries a pointer to the pixel data of a pixbuf.

Returns:
  A pointer to the pixbuf's pixel data. Please see <xref linkend="image-data"> for information about how the pixel data is stored in memory.

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 Glib::ObjectBase.

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

Provides access to the underlying C GObject.

Reimplemented from Glib::ObjectBase.

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.

void Gdk::Pixbuf::render_pixmap_and_mask | ( | Glib::RefPtr< Pixmap >& | pixmap_return,
|  | Glib::RefPtr< Bitmap >& | mask_return,
|  | int | alpha_threshold |
| ) |  |  |

void Gdk::Pixbuf::render_pixmap_and_mask_for_colormap | ( | const Glib::RefPtr< Colormap >& | colormap,
|  | Glib::RefPtr< Pixmap >& | pixmap_return,
|  | Glib::RefPtr< Bitmap >& | mask_return,
|  | int | alpha_threshold |
| ) |  |  |

void Gdk::Pixbuf::render_threshold_alpha | ( | const Glib::RefPtr< Gdk::Bitmap >& | bitmap,
|  | int | src_x,
|  | int | src_y,
|  | int | dest_x,
|  | int | dest_y,
|  | int | width,
|  | int | height,
|  | int | alpha_threshold |
| ) |  |  |

Takes the opacity values in a rectangular portion of a pixbuf and thresholds them to produce a bi-level alpha mask that can be used as a clipping mask for a drawable.

Parameters:

  | bitmap | Bitmap where the bilevel mask will be painted to.
  | src_x | Source X coordinate.
  | src_y | Source Y coordinate.
  | dest_x | Destination X coordinate.
  | dest_y | Destination Y coordinate.
  | width | Width of region to threshold, or -1 to use pixbuf width.
  | height | Height of region to threshold, or -1 to use pixbuf height.
  | alpha_threshold | Opacity values below this will be painted as zero; all other values will be painted as one.

void Gdk::Pixbuf::render_to_drawable | ( | const Glib::RefPtr< Drawable >& | drawable,
|  | const Glib::RefPtr< Gdk::GC >& | gc,
|  | int | src_x,
|  | int | src_y,
|  | int | dest_x,
|  | int | dest_y,
|  | int | width,
|  | int | height,
|  | RgbDither | dither,
|  | int | x_dither,
|  | int | y_dither |
| ) |  |  |

void Gdk::Pixbuf::render_to_drawable_alpha | ( | const Glib::RefPtr< Drawable >& | drawable,
|  | int | src_x,
|  | int | src_y,
|  | int | dest_x,
|  | int | dest_y,
|  | int | width,
|  | int | height,
|  | PixbufAlphaMode | alpha_mode,
|  | int | alpha_threshold,
|  | RgbDither | dither,
|  | int | x_dither,
|  | int | y_dither |
| ) |  |  |

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

Modifies saturation and optionally pixelates src, placing the result in dest.

src and dest may be the same pixbuf with no ill effects. If saturation is 1.0 then saturation is not changed. If it's less than 1.0, saturation is reduced (the image turns toward grayscale); if greater than 1.0, saturation is increased (the image gets more vivid colors). If pixelate is `true`, then pixels are faded in a checkerboard pattern to create a pixelated image. src and dest must have the same image format, size, and rowstride.

Parameters:

  | dest | Place to write modified version of src.
  | saturation | Saturation factor.
  | pixelate | Whether to pixelate.

void Gdk::Pixbuf::save | ( | const std::string & | filename,
|  | const Glib::ustring & | type,
|  | const Glib::StringArrayHandle & | option_keys,
|  | const Glib::StringArrayHandle & | 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 Gdk::Pixbuf::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. TThe list of all writable formats can be determined by using Gdk::Pixbuf::get_formats() with Gdk::PixbufFormat::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 Glib::StringArrayHandle & | option_keys,
|  | const Glib::StringArrayHandle & | 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

Creates a transformation of the source image src by scaling by scale_x and scale_y then translating by offset_x and offset_y, then renders the rectangle ( dest_x, dest_y, dest_width, dest_height) of the resulting image onto the destination image replacing the previous contents.

Try to use scale_simple() first, this function is the industrial-strength power tool you can fall back to if scale_simple() isn't powerful enough.

If the source rectangle overlaps the destination rectangle on the same pixbuf, it will be overwritten during the scaling which results in rendering artifacts.

Parameters:

  | dest | The Gdk::Pixbuf into which to render the results.
  | dest_x | The left coordinate for region to render.
  | dest_y | The top coordinate for region to render.
  | dest_width | The width of the region to render.
  | dest_height | The height of the region to render.
  | offset_x | The offset in the X direction (currently rounded to an integer).
  | offset_y | The offset in the Y direction (currently rounded to an integer).
  | scale_x | The scale factor in the X direction.
  | scale_y | The scale factor in the Y direction.
  | interp_type | The interpolation type for the transformation.

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

Create a new Gdk::Pixbuf containing a copy of src scaled to dest_width x dest_height.

Leaves src unaffected. interp_type should be Gdk::INTERP_NEAREST if you want maximum speed (but when scaling down Gdk::INTERP_NEAREST is usually unusably ugly). The default interp_type should be Gdk::INTERP_BILINEAR which offers reasonable quality and speed.

You can scale a sub-portion of src by creating a sub-pixbuf pointing into src; see new_subpixbuf().

For more complicated scaling/compositing see scale() and composite().

Parameters:

  | dest_width | The width of destination image.
  | dest_height | The height of destination image.
  | interp_type | The interpolation type for the transformation.

Returns:
  The new Gdk::Pixbuf, or `0` if not enough memory could be allocated for it.

## 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