Struct gdk_pixbuf::Pixbuf[][src]

pub struct Pixbuf(_);
Expand description

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

Implements

gio::prelude::IconExt, gio::prelude::LoadableIconExt

Implementations

Creates a new 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.

colorspace

Color space for image

has_alpha

Whether the image should have transparency information

bits_per_sample

Number of bits per color sample

width

Width of image in pixels, must be > 0

height

Height of image in pixels, must be > 0

Returns

A newly-created Pixbuf with a reference count of 1, or None if not enough memory could be allocated for the image buffer.

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

data

Image data in 8-bit/sample packed format inside a glib::Bytes

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, must be > 0

height

Height of the image in pixels, must be > 0

rowstride

Distance in bytes between row starts

Returns

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

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

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

resource_path

the path of the resource file

Returns

A newly-created pixbuf, or None 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.

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

The file format is detected automatically. If None 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.

resource_path

the path of the resource file

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

Returns

A newly-created pixbuf, or None 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.

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

The file format is detected automatically. If None 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.

stream

a gio::InputStream to load the pixbuf from

cancellable

optional gio::Cancellable object, None to ignore

Returns

A newly-created pixbuf, or None 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.

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

The file format is detected automatically. If None 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.

stream

a gio::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 gio::Cancellable object, None to ignore

Returns

A newly-created pixbuf, or None 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.

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.

data

Pointer to inline XPM data.

Returns

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

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.

substitute_color

Whether to set a color to zero opacity. If this is false, then the (r, g, b) arguments will be ignored.

r

Red value to substitute.

g

Green value to substitute.

b

Blue value to substitute.

Returns

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

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.

Returns

A newly-created pixbuf, None if not enough memory could be allocated for it, or a reference to the input pixbuf (with an increased reference count).

Creates a transformation of the source image self 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.

dest

the 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)

Creates a transformation of the source image self 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 composite_color_simple() for a simpler variant of this function suitable for many tasks.

dest

the 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

Creates a new Pixbuf by scaling self to dest_width x dest_height and alpha blending the result with a checkboard of colors color1 and color2.

dest_width

the width of destination image

dest_height

the height of destination image

interp_type

the interpolation type for the transformation.

overall_alpha

overall alpha for source image (0..255)

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

Returns

the new Pixbuf, or None if not enough memory could be allocated for it.

Creates a new Pixbuf with a copy of the information in the specified self. Note that this does not copy the options set on the original Pixbuf, use copy_options() for this.

Returns

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

Copies a rectangular area from self 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.

src_x

Source X coordinate within self.

src_y

Source Y coordinate within self.

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.

This is supported on crate feature v2_36 only.

Copy the key/value pair options attached to a 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.

dest_pixbuf

the Pixbuf to copy options to

Returns

true on success.

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.

pixel

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

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

horizontal

true to flip horizontally, false to flip vertically

Returns

the new Pixbuf, or None if not enough memory could be allocated for it.

Queries the number of bits per color sample in a pixbuf.

Returns

Number of bits per color sample.

Returns the length of the pixel data, in bytes.

Returns

The length of the pixel data.

Queries the color space of a pixbuf.

Returns

Color space.

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

Returns

true if it has an alpha channel, false otherwise.

Queries the height of a pixbuf.

Returns

Height in pixels.

Queries the number of channels of a pixbuf.

Returns

Number of channels.

Looks up key in the list of options that may have been attached to the self when it was loaded, or that may have been attached by another function using 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.

key

a nul-terminated string.

Returns

the value associated with key. This is a nul-terminated string that should not be freed or None if key was not found.

Queries the rowstride of a pixbuf, which is the number of bytes between the start of a row and the start of the next row.

Returns

Distance between row starts.

Queries the width of a pixbuf.

Returns

Width in pixels.

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

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

src_x

X coord in self

src_y

Y coord in self

width

width of region in self

height

height of region in self

Returns

a new pixbuf

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

Returns

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 glib::Bytes.

This is supported on crate feature v2_36 only.

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

key

a nul-terminated string representing the key to remove.

Returns

true if an option was removed, false if not.

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

If angle is 0, a copy of self is returned, avoiding any rotation.

angle

the angle to rotate by

Returns

the new Pixbuf, or None if not enough memory could be allocated for it.

Modifies saturation and optionally pixelates self, placing the result in dest. self 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. self and dest must have the same image format, size, and rowstride.

dest

place to write modified version of self

saturation

saturation factor

pixelate

whether to pixelate

Creates a transformation of the source image self 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.

dest

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

Create a new Pixbuf containing a copy of self scaled to dest_width x dest_height. Leaves self unaffected. interp_type should be InterpType::Nearest if you want maximum speed (but when scaling down InterpType::Nearest is usually unusably ugly). The default interp_type should be InterpType::Bilinear which offers reasonable quality and speed.

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

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

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

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 Pixbuf, or None if not enough memory could be allocated for it.

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

key

a nul-terminated string.

value

a nul-terminated string.

Returns

true on success.

This is supported on crate feature v2_36_8 only.

Calculates the rowstride that an image created with those values would have. This is useful for front-ends and backends that want to sanity check image values without needing to create them.

colorspace

Color space for image

has_alpha

Whether the image should have transparency information

bits_per_sample

Number of bits per color sample

width

Width of image in pixels, must be > 0

height

Height of image in pixels, must be > 0

Returns

the rowstride for the given values, or -1 in case of error.

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

Returns

A list of GdkPixbufFormats describing the supported image formats. The list should be freed when it is no longer needed, but the structures themselves are owned by Pixbuf and should not be freed.

This is supported on crate feature v2_40 only.

Initalizes the gdk-pixbuf loader modules referenced by the loaders.cache file present inside that directory.

This is to be used by applications that want to ship certain loaders in a different location from the system ones.

This is needed when the OS or runtime ships a minimal number of loaders so as to reduce the potential attack surface of carefully crafted image files, especially for uncommon file types. Applications that require broader image file types coverage, such as image viewers, would be expected to ship the gdk-pixbuf modules in a separate location, bundled with the application in a separate directory from the OS or runtime- provided modules.

path

Path to directory where the loaders.cache is installed

Creates a Pixbuf from a type implementing Read (like File).

use std::fs::File;
use gdk_pixbuf::Pixbuf;

let f = File::open("some_file.png").expect("failed to open image");
let pixbuf = Pixbuf::from_read(f).expect("failed to load image");

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

filename

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

Returns

A newly-created pixbuf with a reference count of 1, or None 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.

Creates a new pixbuf by loading an image from a file. The file format is detected automatically. If None 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 from_file_at_scale().

filename

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

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

Returns

A newly-created pixbuf with a reference count of 1, or None 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.

Creates a new pixbuf by loading an image from a file. The file format is detected automatically. If None 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.

filename

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

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

Returns

A newly-created pixbuf with a reference count of 1, or None 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.

Queries a pointer to the pixel data of a pixbuf.

Returns

A pointer to the pixbuf’s pixel data. Please see the section on [image data][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.

Parses an image file far enough to determine its format and size.

filename

The name of the file to identify.

Returns

A PixbufFormat describing the image format of the file or None if the image format wasn’t recognized. The return value is owned by Pixbuf and should not be freed.

width

Return location for the width of the image, or None

height

Return location for the height of the image, or None

Asynchronously parses an image file far enough to determine its format and size.

For more details see file_info(), 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_get_file_info_finish() to get the result of the operation.

filename

The name of the file to identify

cancellable

optional gio::Cancellable object, None to ignore

callback

a GAsyncReadyCallback to call when the file info is available

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.

type_

name of file format.

option_keys

name of options to set, None-terminated

option_values

values for named options

Returns

whether an error was set

buffer

location to receive a pointer to the new buffer.

This is supported on crate feature v2_36 only.

Saves self to an output stream.

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

stream

a gio::OutputStream to save the pixbuf to

type_

name of file format

option_keys

name of options to set, None-terminated

option_values

values for named options

cancellable

optional gio::Cancellable object, None to ignore

Returns

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

This is supported on crate feature v2_36 only.

Saves self to an output stream asynchronously.

For more details see 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.

stream

a gio::OutputStream to which to save the pixbuf

type_

name of file format

option_keys

name of options to set, None-terminated

option_values

values for named options

cancellable

optional gio::Cancellable object, None to ignore

callback

a GAsyncReadyCallback to call when the pixbuf is saved

This is supported on crate feature v2_36 only.

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.

filename

name of file to save.

type_

name of file format.

option_keys

name of options to set, None-terminated

option_values

values for named options

Returns

whether an error was set

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Returns the type identifier of Self.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Upcasts an object to a superclass or interface T. Read more

Upcasts an object to a reference of its superclass or interface T. Read more

Tries to downcast to a subclass or interface implementor T. Read more

Tries to downcast to a reference of its subclass or interface implementor T. Read more

Tries to cast to an object of type T. This handles upcasting, downcasting and casting between interface and interface implementors. All checks are performed at runtime, while downcast and upcast will do many checks at compile-time already. Read more

Tries to cast to reference to an object of type T. This handles upcasting, downcasting and casting between interface and interface implementors. All checks are performed at runtime, while downcast and upcast will do many checks at compile-time already. Read more

Casts to T unconditionally. Read more

Casts to &T unconditionally. Read more

Performs the conversion.

Checks if two icons are equal. Read more

Serializes a Icon into a glib::Variant. An equivalent Icon can be retrieved back by calling Icon::deserialize() on the returned value. As serialization will avoid using raw icon data when possible, it only makes sense to transfer the glib::Variant between processes on the same machine, (as opposed to over the network), and within the same file system namespace. Read more

Generates a textual representation of self that can be used for serialization such as when passing self to a different process or saving it to persistent storage. Use Icon::for_string() to get self back from the returned string. Read more

Performs the conversion.

Loads a loadable icon. For the asynchronous version of this function, see load_async(). Read more

Loads an icon asynchronously. To finish this function, see g_loadable_icon_load_finish(). For the synchronous, blocking version of this function, see load(). Read more

Returns true if the object is an instance of (can be cast to) T.

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Same as connect but takes a SignalId instead of a signal name.

Same as connect_local but takes a SignalId instead of a signal name.

Same as connect_unsafe but takes a SignalId instead of a signal name.

Emit signal by signal id.

Emit signal with details by signal id.

Emit signal by it’s name.

Same as emit but takes Value for the arguments.

Same as emit_by_name but takes Value for the arguments.

Same as emit_with_details but takes Value for the arguments.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Returns a SendValue clone of self.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.