Class: GdkPixbuf::Pixbuf

Inherits:
Object
  • Object
show all
Defined in:
(unknown)

Overview

This is the main structure in the gdk-pixbuf library. It is used to represent images. It contains information about the image’s pixel data, its color space, bits per sample, width and height, and the rowstride (the number of bytes between the start of one row and the start of the next).

Instance Method Summary collapse

Instance Method Details

#add_alpha(substitute_color, r, g, b) ⇒ GdkPixbuf::Pixbuf

Takes an existing pixbuf and adds an alpha channel to it. If the existing pixbuf already had an alpha channel, the channel values are copied from the original; otherwise, the alpha channel is initialized to 255 (full opacity).

If substitute_color is true, then the color specified by (r, g, b) will be assigned zero opacity. That is, if you pass (255, 255, 255) for the substitute color, all white pixels will become fully transparent. is false, then the (r, g, b) arguments will be ignored.

Parameters:

  • substitute_color (TrueClass)

    Whether to set a color to zero opacity. If this

  • r (Integer)

    Red value to substitute.

  • g (Integer)

    Green value to substitute.

  • b (Integer)

    Blue value to substitute.

Returns:

#apply_embedded_orientationGdkPixbuf::Pixbuf

Takes an existing pixbuf and checks for the presence of an associated “orientation” option, which may be provided by the jpeg loader (which reads the exif orientation tag) or the tiff loader (which reads the tiff orientation tag, and compensates it for the partial transforms performed by libtiff). If an orientation option/tag is present, the appropriate transform will be performed so that the pixbuf is oriented correctly. not enough memory could be allocated for it, or a reference to the input pixbuf (with an increased reference count).

Returns:

#bits_per_sampleInteger

The number of bits per sample. Currently only 8 bit per sample are supported.

Returns:

  • (Integer)

    bits-per-sample

#bits_per_sample=(bits_per_sample) ⇒ Integer

The number of bits per sample. Currently only 8 bit per sample are supported.

Parameters:

  • bits_per_sample (Integer)

Returns:

  • (Integer)

    bits-per-sample

  • (Integer)

    bits-per-sample

#byte_lengthInteger

Returns the length of the pixel data, in bytes.

Returns:

  • (Integer)

    The length of the pixel data.

#colorspaceGdkPixbuf::Colorspace

Returns colorspace.

Returns:

#colorspace=(colorspace) ⇒ GdkPixbuf::Colorspace

Parameters:

Returns:

#composite(dest, dest_x, dest_y, dest_width, dest_height, offset_x, offset_y, scale_x, scale_y, interp_type, overall_alpha) ⇒ nil

Creates a transformation of the source image src by scaling by scale_x and scale_y then translating by offset_x and offset_y. This gives an image in the coordinates of the destination pixbuf. The rectangle (dest_x, dest_y, dest_width, dest_height) is then alpha blended onto the corresponding rectangle of the original destination image.

When the destination rectangle contains parts not in the source image, the data at the edges of the source image is replicated to infinity.

![](composite.png)

Parameters:

  • dest (GdkPixbuf::Pixbuf)

    the Gdk::Pixbuf into which to render the results

  • dest_x (Integer)

    the left coordinate for region to render

  • dest_y (Integer)

    the top coordinate for region to render

  • dest_width (Integer)

    the width of the region to render

  • dest_height (Integer)

    the height of the region to render

  • offset_x (Float)

    the offset in the X direction (currently rounded to an integer)

  • offset_y (Float)

    the offset in the Y direction (currently rounded to an integer)

  • scale_x (Float)

    the scale factor in the X direction

  • scale_y (Float)

    the scale factor in the Y direction

  • interp_type (GdkPixbuf::InterpType)

    the interpolation type for the transformation.

  • overall_alpha (Integer)

    overall alpha for source image (0..255)

Returns:

  • (nil)

#composite_color(dest, dest_x, dest_y, dest_width, dest_height, offset_x, offset_y, scale_x, scale_y, interp_type, overall_alpha, check_x, check_y, check_size, color1, color2) ⇒ nil

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 alpha blends 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.

If the source image has no alpha channel, and overall_alpha is 255, a fast path is used which omits the alpha blending and just performs the scaling.

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

Parameters:

  • dest (GdkPixbuf::Pixbuf)

    the Gdk::Pixbuf into which to render the results

  • dest_x (Integer)

    the left coordinate for region to render

  • dest_y (Integer)

    the top coordinate for region to render

  • dest_width (Integer)

    the width of the region to render

  • dest_height (Integer)

    the height of the region to render

  • offset_x (Float)

    the offset in the X direction (currently rounded to an integer)

  • offset_y (Float)

    the offset in the Y direction (currently rounded to an integer)

  • scale_x (Float)

    the scale factor in the X direction

  • scale_y (Float)

    the scale factor in the Y direction

  • interp_type (GdkPixbuf::InterpType)

    the interpolation type for the transformation.

  • overall_alpha (Integer)

    overall alpha for source image (0..255)

  • check_x (Integer)

    the X offset for the checkboard (origin of checkboard is at -check_x, -check_y)

  • check_y (Integer)

    the Y offset for the checkboard

  • check_size (Integer)

    the size of checks in the checkboard (must be a power of two)

  • color1 (Integer)

    the color of check at upper left

  • color2 (Integer)

    the color of the other check

Returns:

  • (nil)

#composite_color_simple(dest_width, dest_height, interp_type, overall_alpha, check_size, color1, color2) ⇒ GdkPixbuf::Pixbuf

Creates a new Gdk::Pixbuf by scaling src to dest_width x dest_height and alpha blending the result with a checkboard of colors color1 and color2. allocated for it.

Parameters:

  • dest_width (Integer)

    the width of destination image

  • dest_height (Integer)

    the height of destination image

  • interp_type (GdkPixbuf::InterpType)

    the interpolation type for the transformation.

  • overall_alpha (Integer)

    overall alpha for source image (0..255)

  • check_size (Integer)

    the size of checks in the checkboard (must be a power of two)

  • color1 (Integer)

    the color of check at upper left

  • color2 (Integer)

    the color of the other check

Returns:

#copyGdkPixbuf::Pixbuf

Creates a new Gdk::Pixbuf with a copy of the information in the specified pixbuf. Note that this does not copy the options set on the original Gdk::Pixbuf, use gdk_pixbuf_copy_options() for this. not enough memory could be allocated.

Returns:

  • (GdkPixbuf::Pixbuf)

    A newly-created pixbuf with a reference count of 1, or nil if

#copy_area(src_x, src_y, width, height, dest_pixbuf, dest_x, dest_y) ⇒ nil

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 (Integer)

    Source X coordinate within src_pixbuf.

  • src_y (Integer)

    Source Y coordinate within src_pixbuf.

  • width (Integer)

    Width of the area to copy.

  • height (Integer)

    Height of the area to copy.

  • dest_pixbuf (GdkPixbuf::Pixbuf)

    Destination pixbuf.

  • dest_x (Integer)

    X coordinate within dest_pixbuf.

  • dest_y (Integer)

    Y coordinate within dest_pixbuf.

Returns:

  • (nil)

#copy_options(dest_pixbuf) ⇒ TrueClass

Copy the key/value pair options attached to a Gdk::Pixbuf to another. This is useful to keep original metadata after having manipulated a file. However be careful to remove metadata which you’ve already applied, such as the “orientation” option after rotating the image.

Parameters:

Returns:

  • (TrueClass)

    true on success.

#fill(pixel) ⇒ nil

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 (Integer)

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

Returns:

  • (nil)

#flip(horizontal) ⇒ GdkPixbuf::Pixbuf

Flips a pixbuf horizontally or vertically and returns the result in a new pixbuf. if not enough memory could be allocated for it.

Parameters:

  • horizontal (TrueClass)

    true to flip horizontally, false to flip vertically

Returns:

#get_option(key) ⇒ String

Looks up key in the list of options that may have been attached to the pixbuf when it was loaded, or that may have been attached by another function using gdk_pixbuf_set_option().

For instance, the ANI loader provides “Title” and “Artist” options. The ICO, XBM, and XPM loaders provide “x_hot” and “y_hot” hot-spot options for cursor definitions. The PNG loader provides the tEXt ancillary chunk key/value pairs as options. Since 2.12, the TIFF and JPEG loaders return an “orientation” option string that corresponds to the embedded TIFF/Exif orientation tag (if present). Since 2.32, the TIFF loader sets the “multipage” option string to “yes” when a multi-page TIFF is loaded. Since 2.32 the JPEG and PNG loaders set “x-dpi” and “y-dpi” if the file contains image density information in dots per inch. Since 2.36.6, the JPEG loader sets the “comment” option with the comment EXIF tag. string that should not be freed or nil if key was not found.

Parameters:

  • key (String)

    a nul-terminated string.

Returns:

  • (String)

    the value associated with key. This is a nul-terminated

#get_pixels_with_length(length) ⇒ Array<Integer>

Queries a pointer to the pixel data of a pixbuf. pixel data. Please see the section on [image data] for information about how the pixel data is stored in memory.

This function will cause an implicit copy of the pixbuf data if the pixbuf was created from read-only data.

Parameters:

  • length (Integer)

    The length of the binary data.

Returns:

  • (Array<Integer>)

    A pointer to the pixbuf’s

#has_alphaTrueClass

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

Returns:

  • (TrueClass)

    true if it has an alpha channel, false otherwise.

#has_alpha=(has_alpha) ⇒ TrueClass

Parameters:

  • has_alpha (TrueClass)

Returns:

  • (TrueClass)

    has-alpha

  • (TrueClass)

    has-alpha

#has_alpha?TrueClass

Returns has-alpha.

Returns:

  • (TrueClass)

    has-alpha

#heightInteger

Returns height.

Returns:

  • (Integer)

    height

#height=(height) ⇒ Integer

Parameters:

  • height (Integer)

Returns:

  • (Integer)

    height

  • (Integer)

    height

#n_channelsInteger

The number of samples per pixel. Currently, only 3 or 4 samples per pixel are supported.

Returns:

  • (Integer)

    n-channels

#n_channels=(n_channels) ⇒ Integer

The number of samples per pixel. Currently, only 3 or 4 samples per pixel are supported.

Parameters:

  • n_channels (Integer)

Returns:

  • (Integer)

    n-channels

  • (Integer)

    n-channels

#new(colorspace, has_alpha, bits_per_sample, width, height) ⇒ GdkPixbuf::Pixbuf

Creates a new Gdk::Pixbuf structure and allocates a buffer for it. The buffer has an optimal rowstride. Note that the buffer is not cleared; you will have to fill it completely yourself. nil if not enough memory could be allocated for the image buffer.

Parameters:

  • colorspace (GdkPixbuf::Colorspace)

    Color space for image

  • has_alpha (TrueClass)

    Whether the image should have transparency information

  • bits_per_sample (Integer)

    Number of bits per color sample

  • width (Integer)

    Width of image in pixels, must be > 0

  • height (Integer)

    Height of image in pixels, must be > 0

Returns:

  • (GdkPixbuf::Pixbuf)

    A newly-created Gdk::Pixbuf with a reference count of 1, or

#new_from_bytes(data, colorspace, has_alpha, bits_per_sample, width, height, rowstride) ⇒ GdkPixbuf::Pixbuf

Creates a new Gdk::Pixbuf out of in-memory readonly image data. Currently only RGB images with 8 bits per sample are supported. This is the #GBytes variant of gdk_pixbuf_new_from_data().

Parameters:

  • data (GLib::Bytes)

    Image data in 8-bit/sample packed format inside a #GBytes

  • colorspace (GdkPixbuf::Colorspace)

    Colorspace for the image data

  • has_alpha (TrueClass)

    Whether the data has an opacity channel

  • bits_per_sample (Integer)

    Number of bits per sample

  • width (Integer)

    Width of the image in pixels, must be > 0

  • height (Integer)

    Height of the image in pixels, must be > 0

  • rowstride (Integer)

    Distance in bytes between row starts

Returns:

  • (GdkPixbuf::Pixbuf)

    A newly-created Gdk::Pixbuf structure with a reference count of 1.

#new_from_data(data, colorspace, has_alpha, bits_per_sample, width, height, rowstride, destroy_fn, destroy_fn_data) ⇒ GdkPixbuf::Pixbuf

Creates a new Gdk::Pixbuf out of in-memory image data. Currently only RGB images with 8 bits per sample are supported.

Since you are providing a pre-allocated pixel buffer, you must also specify a way to free that data. This is done with a function of type Gdk::PixbufDestroyNotify. When a pixbuf created with is finalized, your destroy notification function will be called, and it is its responsibility to free the pixel array.

See also gdk_pixbuf_new_from_bytes(). drops to zero, or nil if the data should not be freed

Parameters:

  • data (Array<Integer>)

    Image data in 8-bit/sample packed format

  • colorspace (GdkPixbuf::Colorspace)

    Colorspace for the image data

  • has_alpha (TrueClass)

    Whether the data has an opacity channel

  • bits_per_sample (Integer)

    Number of bits per sample

  • width (Integer)

    Width of the image in pixels, must be > 0

  • height (Integer)

    Height of the image in pixels, must be > 0

  • rowstride (Integer)

    Distance in bytes between row starts

  • destroy_fn (GdkPixbuf::PixbufDestroyNotify)

    Function used to free the data when the pixbuf’s reference count

  • destroy_fn_data (GObject)

    Closure data to pass to the destroy notification function

Returns:

  • (GdkPixbuf::Pixbuf)

    A newly-created Gdk::Pixbuf structure with a reference count of 1.

#new_from_file(filename) ⇒ GdkPixbuf::Pixbuf

Creates a new pixbuf by loading an image from a file. The file format is detected automatically. If nil is returned, then error will be set. Possible errors are in the #GDK_PIXBUF_ERROR and #G_FILE_ERROR domains. 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.

Parameters:

  • filename (GdkPixbuf::filename)

    Name of file to load, in the GLib file name encoding

Returns:

  • (GdkPixbuf::Pixbuf)

    A newly-created pixbuf with a reference count of 1, or nil if

#new_from_file_at_scale(filename, width, height, preserve_aspect_ratio) ⇒ GdkPixbuf::Pixbuf

Creates a new pixbuf by loading an image from a file. The file format is detected automatically. If nil is returned, then error will be set. Possible errors are in the #GDK_PIXBUF_ERROR and #G_FILE_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. Negative values for width and height are allowed since 2.8. 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.

Parameters:

  • filename (GdkPixbuf::filename)

    Name of file to load, in the GLib file name encoding

  • width (Integer)

    The width the image should have or -1 to not constrain the width

  • height (Integer)

    The height the image should have or -1 to not constrain the height

  • preserve_aspect_ratio (TrueClass)

    true to preserve the image’s aspect ratio

Returns:

#new_from_file_at_size(filename, width, height) ⇒ GdkPixbuf::Pixbuf

Creates a new pixbuf by loading an image from a file. The file format is detected automatically. If nil is returned, then error will be set. Possible errors are in the #GDK_PIXBUF_ERROR and #G_FILE_ERROR domains.

The image will be scaled to fit in the requested size, preserving the image’s aspect ratio. Note that the returned pixbuf may be smaller than width x height, if the aspect ratio requires it. To load and image at the requested size, regardless of aspect ratio, use gdk_pixbuf_new_from_file_at_scale(). nil 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.

Parameters:

  • filename (GdkPixbuf::filename)

    Name of file to load, in the GLib file name encoding

  • width (Integer)

    The width the image should have or -1 to not constrain the width

  • height (Integer)

    The height the image should have or -1 to not constrain the height

Returns:

#new_from_inline(data_length, data, copy_pixels) ⇒ GdkPixbuf::Pixbuf

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.

gdk-pixbuf ships with a program called [gdk-pixbuf-csource], which allows for conversion of Gdk::Pixbufs into such a inline representation. In almost all cases, you should pass the ‘–raw` option 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 and disable length checks, since things will always succeed: |[ pixbuf = gdk_pixbuf_new_from_inline (-1, myimage_inline, FALSE, NULL); ]|

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 (Integer)

    Length in bytes of the data argument or -1 to disable length checks

  • data (Array<Integer>)

    Byte data containing a serialized Gdk::Pixdata structure

  • copy_pixels (TrueClass)

    Whether to copy the pixel data, or use direct pointers data for the resulting pixbuf

Returns:

  • (GdkPixbuf::Pixbuf)

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

#new_from_resource(resource_path) ⇒ GdkPixbuf::Pixbuf

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

The file format is detected automatically. If nil is returned, then error will be set. 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.

Parameters:

  • resource_path (String)

    the path of the resource file

Returns:

#new_from_resource_at_scale(resource_path, width, height, preserve_aspect_ratio) ⇒ GdkPixbuf::Pixbuf

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

The file format is detected automatically. If nil is returned, then error will be set.

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

Parameters:

  • resource_path (String)

    the path of the resource file

  • width (Integer)

    The width the image should have or -1 to not constrain the width

  • height (Integer)

    The height the image should have or -1 to not constrain the height

  • preserve_aspect_ratio (TrueClass)

    true to preserve the image’s aspect ratio

Returns:

#new_from_stream(stream, cancellable) ⇒ GdkPixbuf::Pixbuf

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

The file format is detected automatically. If nil 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 %G_IO_ERROR_CANCELLED will be returned. Other possible errors are in the #GDK_PIXBUF_ERROR and %G_IO_ERROR domains.

The stream is not closed. 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.

Parameters:

Returns:

#new_from_stream_at_scale(stream, width, height, preserve_aspect_ratio, cancellable) ⇒ GdkPixbuf::Pixbuf

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

The file format is detected automatically. If nil 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 %G_IO_ERROR_CANCELLED will be returned. Other possible errors are in the #GDK_PIXBUF_ERROR and %G_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. If both width and height are given, this function will behave as if the smaller of the two values is passed as -1.

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

Parameters:

  • stream (Gio::InputStream)

    a GInput::Stream to load the pixbuf from

  • width (Integer)

    The width the image should have or -1 to not constrain the width

  • height (Integer)

    The height the image should have or -1 to not constrain the height

  • preserve_aspect_ratio (TrueClass)

    true to preserve the image’s aspect ratio

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

Returns:

#new_from_stream_finish(async_result) ⇒ GdkPixbuf::Pixbuf

Finishes an asynchronous pixbuf creation operation started with gdk_pixbuf_new_from_stream_async(). object with g_object_unref().

Parameters:

Returns:

#new_from_xpm_data(data) ⇒ GdkPixbuf::Pixbuf

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 (Array<String>)

    Pointer to inline XPM data.

Returns:

#new_subpixbuf(src_x, src_y, width, height) ⇒ GdkPixbuf::Pixbuf

Creates a new pixbuf which represents a sub-region of src_pixbuf. The new pixbuf shares its pixels with the original pixbuf, so writing to one affects both. The new pixbuf holds a reference to src_pixbuf, so src_pixbuf will not be finalized until the new pixbuf is finalized.

Note that if src_pixbuf is read-only, this function will force it to be mutable.

Parameters:

  • src_x (Integer)

    X coord in src_pixbuf

  • src_y (Integer)

    Y coord in src_pixbuf

  • width (Integer)

    width of region in src_pixbuf

  • height (Integer)

    height of region in src_pixbuf

Returns:

#optionsGLib::HashTable

Returns a GHash::Table with a list of all the options that may have been attached to the pixbuf when it was loaded, or that may have been attached by another function using gdk_pixbuf_set_option().

See gdk_pixbuf_get_option() for more details.

Returns:

  • (GLib::HashTable)

    a GHash::Table of key/values

#pixel_bytesGLib::Bytes

Returns pixel-bytes.

Returns:

  • (GLib::Bytes)

    pixel-bytes

#pixel_bytes=(pixel_bytes) ⇒ GLib::Bytes

Parameters:

  • pixel_bytes (GLib::Bytes)

Returns:

  • (GLib::Bytes)

    pixel-bytes

  • (GLib::Bytes)

    pixel-bytes

#pixelsGObject

Returns pixels.

Returns:

  • (GObject)

    pixels

#pixels=(pixels) ⇒ GObject

Parameters:

  • pixels (GObject)

Returns:

  • (GObject)

    pixels

  • (GObject)

    pixels

#read_pixel_bytesGLib::Bytes

Provides a #GBytes buffer containing the raw pixel data; the data must not be modified. This function allows skipping the implicit copy that must be made if gdk_pixbuf_get_pixels() is called on a read-only pixbuf.

Returns:

  • (GLib::Bytes)

    A new reference to a read-only copy of the pixel data. Note that for mutable pixbufs, this function will incur a one-time copy of the pixel data for conversion into the returned #GBytes.

#read_pixelsInteger

Provides a read-only pointer to the raw pixel data; must not be modified. This function allows skipping the implicit copy that must be made if gdk_pixbuf_get_pixels() is called on a read-only pixbuf.

Returns:

  • (Integer)

    a read-only pointer to the raw pixel data

#refGdkPixbuf::Pixbuf

Adds a reference to a pixbuf.

Returns:

#remove_option(key) ⇒ TrueClass

Remove the key/value pair option attached to a Gdk::Pixbuf.

Parameters:

  • key (String)

    a nul-terminated string representing the key to remove.

Returns:

  • (TrueClass)

    true if an option was removed, false if not.

#rotate_simple(angle) ⇒ GdkPixbuf::Pixbuf

Rotates a pixbuf by a multiple of 90 degrees, and returns the result in a new pixbuf.

If angle is 0, a copy of src is returned, avoiding any rotation. if not enough memory could be allocated for it.

Parameters:

Returns:

#rowstrideInteger

The number of bytes between the start of a row and the start of the next row. This number must (obviously) be at least as large as the width of the pixbuf.

Returns:

  • (Integer)

    rowstride

#rowstride=(rowstride) ⇒ Integer

The number of bytes between the start of a row and the start of the next row. This number must (obviously) be at least as large as the width of the pixbuf.

Parameters:

  • rowstride (Integer)

Returns:

  • (Integer)

    rowstride

  • (Integer)

    rowstride

#saturate_and_pixelate(dest, saturation, pixelate) ⇒ nil

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 (GdkPixbuf::Pixbuf)

    place to write modified version of src

  • saturation (GdkPixbuf::gfloat)

    saturation factor

  • pixelate (TrueClass)

    whether to pixelate

Returns:

  • (nil)

#save(filename, type, error, array) ⇒ TrueClass

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 in the following way:

|[ void add_if_writable (GdkPixbufFormat *data, GSList **list)

if (gdk_pixbuf_format_is_writable (data))
  *list = g_slist_prepend (*list, data);

GSList *formats = gdk_pixbuf_get_formats (); GSList *writable_formats = NULL; g_slist_foreach (formats, add_if_writable, &writable_formats); g_slist_free (formats); ]|

If error is set, false will be returned. Possible errors include those in the #GDK_PIXBUF_ERROR domain and those in the #G_FILE_ERROR domain.

The variable argument list should be nil-terminated; if not empty, it should contain pairs of strings that modify the save parameters. For example: |[ gdk_pixbuf_save (pixbuf, handle, “jpeg”, &error, “quality”, “100”, NULL); ]|

Currently only few parameters exist. JPEG images can be saved with a “quality” parameter; its value should be in the range [0,100]. JPEG and PNG density can be set by setting the “x-dpi” and “y-dpi” parameters to the appropriate values in dots per inch.

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. The PNG compression level can be specified using the “compression” parameter; it’s value is in an integer in the range of [0,9].

ICC color profiles can also be embedded into PNG, JPEG and TIFF images. The “icc-profile” value should be the complete ICC profile encoded into base64.

|[ gchar *contents; gchar *contents_encode; gsize length; g_file_get_contents (“/home/hughsie/.color/icc/L225W.icm”, &contents, &length, NULL); contents_encode = g_base64_encode ((const guchar *) contents, length); gdk_pixbuf_save (pixbuf, handle, “png”, &error, “icc-profile”, contents_encode, NULL); ]|

TIFF images recognize: (1) a “bits-per-sample” option (integer) which can be either 1 for saving bi-level CCITTFAX4 images, or 8 for saving 8-bits per sample; (2) a “compression” option (integer) which can be 1 for no compression, 2 for Huffman, 5 for LZW, 7 for JPEG and 8 for DEFLATE (see the libtiff documentation and tiff.h for all supported codec values); (3) an “icc-profile” option (zero-terminated string) containing a base64 encoded ICC color profile.

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 (GdkPixbuf::filename)

    name of file to save.

  • type (String)

    name of file format.

  • error (GLib::Error)

    return location for error, or nil

  • array (Array)

    list of key-value save options, followed by nil

Returns:

  • (TrueClass)

    whether an error was set

#save_to_buffer(buffer, buffer_size, type, error, array) ⇒ TrueClass

Saves pixbuf to a new buffer in format type, which is currently “jpeg”, “png”, “tiff”, “ico” or “bmp”. This is a convenience function that uses gdk_pixbuf_save_to_callback() to do the real work. Note that the buffer is not nul-terminated and may contain embedded nuls. If error is set, false will be returned and buffer will be set to nil. Possible errors include those in the #GDK_PIXBUF_ERROR domain.

See gdk_pixbuf_save() for more details.

Parameters:

  • buffer (Array<Integer>)

    location to receive a pointer to the new buffer.

  • buffer_size (Integer)

    location to receive the size of the new buffer.

  • type (String)

    name of file format.

  • error (GLib::Error)

    return location for error, or nil

  • array (Array)

    list of key-value save options

Returns:

  • (TrueClass)

    whether an error was set

#save_to_bufferv(buffer, buffer_size, type, option_keys, option_values) ⇒ TrueClass

Saves pixbuf to a new buffer in format type, which is currently “jpeg”, “tiff”, “png”, “ico” or “bmp”. See gdk_pixbuf_save_to_buffer() for more details.

Parameters:

  • buffer (Array<Integer>)

    location to receive a pointer to the new buffer.

  • buffer_size (Integer)

    location to receive the size of the new buffer.

  • type (String)

    name of file format.

  • option_keys (Array<String>)

    name of options to set, nil-terminated

  • option_values (Array<String>)

    values for named options

Returns:

  • (TrueClass)

    whether an error was set

#save_to_callback(save_func, user_data, type, error, array) ⇒ TrueClass

Saves pixbuf in format type by feeding the produced data to a callback. Can be used when you want to store the image to something other than a file, such as an in-memory buffer or a socket. If error is set, false will be returned. Possible errors include those in the #GDK_PIXBUF_ERROR domain and whatever the save function generates.

See gdk_pixbuf_save() for more details.

Parameters:

  • save_func (GdkPixbuf::PixbufSaveFunc)

    a function that is called to save each block of data that the save routine generates.

  • user_data (GObject)

    user data to pass to the save function.

  • type (String)

    name of file format.

  • error (GLib::Error)

    return location for error, or nil

  • array (Array)

    list of key-value save options

Returns:

  • (TrueClass)

    whether an error was set

#save_to_callbackv(save_func, user_data, type, option_keys, option_values) ⇒ TrueClass

Saves pixbuf to a callback in format type, which is currently “jpeg”, “png”, “tiff”, “ico” or “bmp”. If error is set, false will be returned. See gdk_pixbuf_save_to_callback () for more details.

Parameters:

  • save_func (GdkPixbuf::PixbufSaveFunc)

    a function that is called to save each block of data that the save routine generates.

  • user_data (GObject)

    user data to pass to the save function.

  • type (String)

    name of file format.

  • option_keys (Array<String>)

    name of options to set, nil-terminated

  • option_values (Array<String>)

    values for named options

Returns:

  • (TrueClass)

    whether an error was set

#save_to_stream(stream, type, cancellable, error, array) ⇒ TrueClass

Saves pixbuf to an output stream.

Supported file formats are currently “jpeg”, “tiff”, “png”, “ico” or “bmp”. See gdk_pixbuf_save_to_buffer() for more details.

The cancellable can be used to abort the operation from another thread. If the operation was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. Other possible errors are in the #GDK_PIXBUF_ERROR and %G_IO_ERROR domains.

The stream is not closed.

Parameters:

  • stream (Gio::OutputStream)

    a GOutput::Stream to save the pixbuf to

  • type (String)

    name of file format

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

  • error (GLib::Error)

    return location for error, or nil

  • array (Array)

    list of key-value save options

Returns:

  • (TrueClass)

    true if the pixbuf was saved successfully, false if an error was set.

#save_to_stream_async(stream, type, cancellable, callback, user_data, array) ⇒ nil

Saves pixbuf to an output stream asynchronously.

For more details see gdk_pixbuf_save_to_stream(), which is the synchronous version of this function.

When the operation is finished, callback will be called in the main thread. You can then call gdk_pixbuf_save_to_stream_finish() to get the result of the operation.

Parameters:

  • stream (Gio::OutputStream)

    a GOutput::Stream to which to save the pixbuf

  • type (String)

    name of file format

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

  • callback (Gio::AsyncReadyCallback)

    a GAsync::ReadyCallback to call when the pixbuf is saved

  • user_data (GObject)

    the data to pass to the callback function

  • array (Array)

    list of key-value save options

Returns:

  • (nil)

#save_to_streamv(stream, type, option_keys, option_values, cancellable) ⇒ TrueClass

Saves pixbuf to an output stream.

Supported file formats are currently “jpeg”, “tiff”, “png”, “ico” or “bmp”. See gdk_pixbuf_save_to_stream() for more details.

Parameters:

  • stream (Gio::OutputStream)

    a GOutput::Stream to save the pixbuf to

  • type (String)

    name of file format

  • option_keys (Array<String>)

    name of options to set, nil-terminated

  • option_values (Array<String>)

    values for named options

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

Returns:

  • (TrueClass)

    true if the pixbuf was saved successfully, false if an error was set.

#save_to_streamv_async(stream, type, option_keys, option_values, cancellable, callback, user_data) ⇒ nil

Saves pixbuf to an output stream asynchronously.

For more details see gdk_pixbuf_save_to_streamv(), which is the synchronous version of this function.

When the operation is finished, callback will be called in the main thread. You can then call gdk_pixbuf_save_to_stream_finish() to get the result of the operation.

Parameters:

  • stream (Gio::OutputStream)

    a GOutput::Stream to which to save the pixbuf

  • type (String)

    name of file format

  • option_keys (Array<String>)

    name of options to set, nil-terminated

  • option_values (Array<String>)

    values for named options

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

  • callback (Gio::AsyncReadyCallback)

    a GAsync::ReadyCallback to call when the pixbuf is saved

  • user_data (GObject)

    the data to pass to the callback function

Returns:

  • (nil)

#savev(filename, type, option_keys, option_values) ⇒ TrueClass

Saves pixbuf to a file in type, which is currently “jpeg”, “png”, “tiff”, “ico” or “bmp”. If error is set, false will be returned. See gdk_pixbuf_save () for more details.

Parameters:

  • filename (GdkPixbuf::filename)

    name of file to save.

  • type (String)

    name of file format.

  • option_keys (Array<String>)

    name of options to set, nil-terminated

  • option_values (Array<String>)

    values for named options

Returns:

  • (TrueClass)

    whether an error was set

#scale(dest, dest_x, dest_y, dest_width, dest_height, offset_x, offset_y, scale_x, scale_y, interp_type) ⇒ nil

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 gdk_pixbuf_scale_simple() first, this function is the industrial-strength power tool you can fall back to if gdk_pixbuf_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 (GdkPixbuf::Pixbuf)

    the Gdk::Pixbuf into which to render the results

  • dest_x (Integer)

    the left coordinate for region to render

  • dest_y (Integer)

    the top coordinate for region to render

  • dest_width (Integer)

    the width of the region to render

  • dest_height (Integer)

    the height of the region to render

  • offset_x (Float)

    the offset in the X direction (currently rounded to an integer)

  • offset_y (Float)

    the offset in the Y direction (currently rounded to an integer)

  • scale_x (Float)

    the scale factor in the X direction

  • scale_y (Float)

    the scale factor in the Y direction

  • interp_type (GdkPixbuf::InterpType)

    the interpolation type for the transformation.

Returns:

  • (nil)

#scale_simple(dest_width, dest_height, interp_type) ⇒ GdkPixbuf::Pixbuf

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 gdk_pixbuf_new_subpixbuf().

If dest_width and dest_height are equal to the src width and height, a copy of src is returned, avoiding any scaling.

For more complicated scaling/alpha blending see gdk_pixbuf_scale() and gdk_pixbuf_composite(). allocated for it.

Parameters:

  • dest_width (Integer)

    the width of destination image

  • dest_height (Integer)

    the height of destination image

  • interp_type (GdkPixbuf::InterpType)

    the interpolation type for the transformation.

Returns:

#set_option(key, value) ⇒ TrueClass

Attaches a key/value pair as an option to a Gdk::Pixbuf. If key already exists in the list of options attached to pixbuf, the new value is ignored and false is returned.

Parameters:

  • key (String)

    a nul-terminated string.

  • value (String)

    a nul-terminated string.

Returns:

  • (TrueClass)

    true on success.

#unrefnil

Removes a reference from a pixbuf.

Returns:

  • (nil)

#widthInteger

Returns width.

Returns:

  • (Integer)

    width

#width=(width) ⇒ Integer

Parameters:

  • width (Integer)

Returns:

  • (Integer)

    width

  • (Integer)

    width