[]Struct gdk_pixbuf::Pixbuf

pub struct Pixbuf(_, _);

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::IconExt, gio::LoadableIconExt

Methods

impl Pixbuf[src]

pub fn new(
    colorspace: Colorspace,
    has_alpha: bool,
    bits_per_sample: i32,
    width: i32,
    height: i32
) -> Option<Pixbuf>
[src]

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.

pub fn new_from_bytes(
    data: &Bytes,
    colorspace: Colorspace,
    has_alpha: bool,
    bits_per_sample: i32,
    width: i32,
    height: i32,
    rowstride: i32
) -> Pixbuf
[src]

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 Pixbuf::new_from_data.

Feature: v2_32

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.

pub fn new_from_inline(data: &[u8], copy_pixels: bool) -> Result<Pixbuf, Error>[src]

Create a 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][gdk-pixbuf-csource], which allows for conversion of GdkPixbufs 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.

Deprecated since 2.32

Use gio::Resource instead.

data_length

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

data

Byte data containing a serialized GdkPixdata structure

copy_pixels

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

Returns

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

pub fn new_from_resource(resource_path: &str) -> Result<Pixbuf, Error>[src]

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.

pub fn new_from_resource_at_scale(
    resource_path: &str,
    width: i32,
    height: i32,
    preserve_aspect_ratio: bool
) -> Result<Pixbuf, Error>
[src]

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.

pub fn new_from_stream<P: IsA<InputStream>, Q: IsA<Cancellable>>(
    stream: &P,
    cancellable: Option<&Q>
) -> Result<Pixbuf, Error>
[src]

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 gio::IOErrorEnum::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.

pub fn new_from_stream_at_scale<P: IsA<InputStream>, Q: IsA<Cancellable>>(
    stream: &P,
    width: i32,
    height: i32,
    preserve_aspect_ratio: bool,
    cancellable: Option<&Q>
) -> Result<Pixbuf, Error>
[src]

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 gio::IOErrorEnum::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.

pub fn new_from_xpm_data(data: &[&str]) -> Pixbuf[src]

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.

pub fn add_alpha(
    &self,
    substitute_color: bool,
    r: u8,
    g: u8,
    b: u8
) -> Option<Pixbuf>
[src]

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.

pub fn apply_embedded_orientation(&self) -> Option<Pixbuf>[src]

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

pub fn composite(
    &self,
    dest: &Pixbuf,
    dest_x: i32,
    dest_y: i32,
    dest_width: i32,
    dest_height: i32,
    offset_x: f64,
    offset_y: f64,
    scale_x: f64,
    scale_y: f64,
    interp_type: InterpType,
    overall_alpha: i32
)
[src]

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)

pub fn composite_color(
    &self,
    dest: &Pixbuf,
    dest_x: i32,
    dest_y: i32,
    dest_width: i32,
    dest_height: i32,
    offset_x: f64,
    offset_y: f64,
    scale_x: f64,
    scale_y: f64,
    interp_type: InterpType,
    overall_alpha: i32,
    check_x: i32,
    check_y: i32,
    check_size: i32,
    color1: u32,
    color2: u32
)
[src]

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 Pixbuf::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

pub fn composite_color_simple(
    &self,
    dest_width: i32,
    dest_height: i32,
    interp_type: InterpType,
    overall_alpha: i32,
    check_size: i32,
    color1: u32,
    color2: u32
) -> Option<Pixbuf>
[src]

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.

pub fn copy(&self) -> Option<Pixbuf>[src]

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 Pixbuf::copy_options for this.

Returns

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

pub fn copy_area(
    &self,
    src_x: i32,
    src_y: i32,
    width: i32,
    height: i32,
    dest_pixbuf: &Pixbuf,
    dest_x: i32,
    dest_y: i32
)
[src]

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.

pub fn copy_options(&self, dest_pixbuf: &Pixbuf) -> bool[src]

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.

Feature: v2_36

dest_pixbuf

the Pixbuf to copy options to

Returns

true on success.

pub fn fill(&self, pixel: u32)[src]

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)

pub fn flip(&self, horizontal: bool) -> Option<Pixbuf>[src]

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.

pub fn get_bits_per_sample(&self) -> i32[src]

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

Returns

Number of bits per color sample.

pub fn get_byte_length(&self) -> usize[src]

Returns the length of the pixel data, in bytes.

Returns

The length of the pixel data.

pub fn get_colorspace(&self) -> Colorspace[src]

Queries the color space of a pixbuf.

Returns

Color space.

pub fn get_has_alpha(&self) -> bool[src]

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

Returns

true if it has an alpha channel, false otherwise.

pub fn get_height(&self) -> i32[src]

Queries the height of a pixbuf.

Returns

Height in pixels.

pub fn get_n_channels(&self) -> i32[src]

Queries the number of channels of a pixbuf.

Returns

Number of channels.

pub fn get_option(&self, key: &str) -> Option<GString>[src]

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

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.

pub fn get_rowstride(&self) -> i32[src]

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.

pub fn get_width(&self) -> i32[src]

Queries the width of a pixbuf.

Returns

Width in pixels.

pub fn new_subpixbuf(
    &self,
    src_x: i32,
    src_y: i32,
    width: i32,
    height: i32
) -> Option<Pixbuf>
[src]

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

pub fn read_pixel_bytes(&self) -> Option<Bytes>[src]

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 Pixbuf::get_pixels is called on a read-only pixbuf.

Feature: v2_32

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.

pub fn remove_option(&self, key: &str) -> bool[src]

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

Feature: v2_36

key

a nul-terminated string representing the key to remove.

Returns

true if an option was removed, false if not.

pub fn rotate_simple(&self, angle: PixbufRotation) -> Option<Pixbuf>[src]

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.

pub fn saturate_and_pixelate(
    &self,
    dest: &Pixbuf,
    saturation: f32,
    pixelate: bool
)
[src]

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

pub fn scale(
    &self,
    dest: &Pixbuf,
    dest_x: i32,
    dest_y: i32,
    dest_width: i32,
    dest_height: i32,
    offset_x: f64,
    offset_y: f64,
    scale_x: f64,
    scale_y: f64,
    interp_type: InterpType
)
[src]

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 Pixbuf::scale_simple first, this function is the industrial-strength power tool you can fall back to if 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.

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.

pub fn scale_simple(
    &self,
    dest_width: i32,
    dest_height: i32,
    interp_type: InterpType
) -> Option<Pixbuf>
[src]

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 Pixbuf::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 Pixbuf::scale and Pixbuf::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.

pub fn set_option(&self, key: &str, value: &str) -> bool[src]

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.

pub fn get_property_pixel_bytes(&self) -> Option<Bytes>[src]

pub fn calculate_rowstride(
    colorspace: Colorspace,
    has_alpha: bool,
    bits_per_sample: i32,
    width: i32,
    height: i32
) -> i32
[src]

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.

Feature: v2_36_8

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.

pub fn get_formats() -> Vec<PixbufFormat>[src]

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

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.

pub fn init_modules(path: &str) -> Result<(), Error>[src]

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.

Feature: v2_40

path

Path to directory where the loaders.cache is installed

impl Pixbuf[src]

pub fn new_from_mut_slice<T: AsMut<[u8]>>(
    data: T,
    colorspace: Colorspace,
    has_alpha: bool,
    bits_per_sample: i32,
    width: i32,
    height: i32,
    row_stride: i32
) -> Pixbuf
[src]

pub fn new_from_file<T: AsRef<Path>>(filename: T) -> Result<Pixbuf, Error>[src]

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.

pub fn new_from_file_at_size<T: AsRef<Path>>(
    filename: T,
    width: i32,
    height: i32
) -> Result<Pixbuf, Error>
[src]

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 Pixbuf::new_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.

pub fn new_from_file_at_scale<T: AsRef<Path>>(
    filename: T,
    width: i32,
    height: i32,
    preserve_aspect_ratio: bool
) -> Result<Pixbuf, Error>
[src]

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.

pub fn new_from_stream_async<'a, P: IsA<InputStream>, Q: IsA<Cancellable>, R: FnOnce(Result<Pixbuf, Error>) + Send + 'static>(
    stream: &P,
    cancellable: Option<&Q>,
    callback: R
)
[src]

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

For more details see Pixbuf::new_from_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 Pixbuf::new_from_stream_finish to get the result of the operation.

stream

a gio::InputStream from which to load the pixbuf

cancellable

optional gio::Cancellable object, None to ignore

callback

a GAsyncReadyCallback to call when the pixbuf is loaded

user_data

the data to pass to the callback function

pub fn new_from_stream_async_future<P: IsA<InputStream> + Clone + 'static>(
    stream: &P
) -> Pin<Box<dyn Future<Output = Result<Pixbuf, Error>> + 'static>>
[src]

pub fn new_from_stream_at_scale_async<'a, P: IsA<InputStream>, Q: IsA<Cancellable>, R: FnOnce(Result<Pixbuf, Error>) + Send + 'static>(
    stream: &P,
    width: i32,
    height: i32,
    preserve_aspect_ratio: bool,
    cancellable: Option<&Q>,
    callback: R
)
[src]

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

For more details see Pixbuf::new_from_stream_at_scale, 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 Pixbuf::new_from_stream_finish to get the result of the operation.

stream

a gio::InputStream from which to load the pixbuf

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

callback

a GAsyncReadyCallback to call when the pixbuf is loaded

user_data

the data to pass to the callback function

pub fn new_from_stream_at_scale_async_future<P: IsA<InputStream> + Clone + 'static>(
    stream: &P,
    width: i32,
    height: i32,
    preserve_aspect_ratio: bool
) -> Pin<Box<dyn Future<Output = Result<Pixbuf, Error>> + 'static>>
[src]

pub unsafe fn get_pixels(&self) -> &mut [u8][src]

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.

pub fn put_pixel(&self, x: i32, y: i32, red: u8, green: u8, blue: u8, alpha: u8)[src]

pub fn get_file_info<T: AsRef<Path>>(
    filename: T
) -> Option<(PixbufFormat, i32, i32)>
[src]

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

filename

The name of the file to identify.

width

Return location for the width of the image, or None

height

Return location for the height of the image, or None

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.

pub fn get_file_info_async<P: IsA<Cancellable>, Q: FnOnce(Result<Option<(PixbufFormat, i32, i32)>, Error>) + Send + 'static, T: AsRef<Path>>(
    filename: T,
    cancellable: Option<&P>,
    callback: Q
)
[src]

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

For more details see Pixbuf::get_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 Pixbuf::get_file_info_finish to get the result of the operation.

Feature: v2_32

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

user_data

the data to pass to the callback function

pub fn get_file_info_async_future<T: AsRef<Path> + Clone + 'static>(
    filename: T
) -> Pin<Box<dyn Future<Output = Result<Option<(PixbufFormat, i32, i32)>, Error>> + 'static>>
[src]

pub fn save_to_bufferv(
    &self,
    type_: &str,
    options: &[(&str, &str)]
) -> Result<Vec<u8>, Error>
[src]

Saves pixbuf to a new buffer in format type_, which is currently "jpeg", "tiff", "png", "ico" or "bmp". See Pixbuf::save_to_buffer for more details.

buffer

location to receive a pointer to the new buffer.

buffer_size

location to receive the size of the new buffer.

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

pub fn save_to_streamv<'a, P: IsA<OutputStream>, Q: IsA<Cancellable>>(
    &self,
    stream: &P,
    type_: &str,
    options: &[(&str, &str)],
    cancellable: Option<&Q>
) -> Result<(), Error>
[src]

Saves self to an output stream.

Supported file formats are currently "jpeg", "tiff", "png", "ico" or "bmp". See Pixbuf::save_to_stream for more details.

Feature: v2_36

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.

pub fn save_to_streamv_async<'a, P: IsA<OutputStream>, Q: IsA<Cancellable>, R: FnOnce(Result<(), Error>) + Send + 'static>(
    &self,
    stream: &P,
    type_: &str,
    options: &[(&str, &str)],
    cancellable: Option<&Q>,
    callback: R
)
[src]

Saves self to an output stream asynchronously.

For more details see 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 Pixbuf::save_to_stream_finish to get the result of the operation.

Feature: v2_36

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

user_data

the data to pass to the callback function

pub fn save_to_streamv_async_future<P: IsA<OutputStream> + Clone + 'static>(
    &self,
    stream: &P,
    type_: &str,
    options: &[(&str, &str)]
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static>>
[src]

pub fn savev<T: AsRef<Path>>(
    &self,
    filename: T,
    type_: &str,
    options: &[(&str, &str)]
) -> Result<(), Error>
[src]

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

impl Clone for Pixbuf

impl Debug for Pixbuf

impl Display for Pixbuf[src]

impl Eq for Pixbuf

impl Hash for Pixbuf

impl IsA<Icon> for Pixbuf

impl IsA<LoadableIcon> for Pixbuf

impl Ord for Pixbuf

impl<T: ObjectType> PartialEq<T> for Pixbuf

impl<T: ObjectType> PartialOrd<T> for Pixbuf

impl StaticType for Pixbuf

Auto Trait Implementations

impl RefUnwindSafe for Pixbuf

impl !Send for Pixbuf

impl !Sync for Pixbuf

impl Unpin for Pixbuf

impl UnwindSafe for Pixbuf

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Super, Sub> CanDowncast<Sub> for Super where
    Sub: IsA<Super>,
    Super: IsA<Super>, 

impl<T> Cast for T where
    T: ObjectType, 

impl<T> From<T> for T[src]

impl<O> IconExt for O where
    O: IsA<Icon>, 

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<O> LoadableIconExt for O where
    O: IsA<LoadableIcon>, 

impl<T> ObjectExt for T where
    T: ObjectType, 

impl<'a, T> ToGlibContainerFromSlice<'a, *const GList> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<List>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<Array>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GList> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<List>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToSendValue for T where
    T: ToValue + SetValue + Send + ?Sized

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> ToValue for T where
    T: SetValue + ?Sized

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = !

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.