gdk4::prelude

Trait TextureExt

Source
pub trait TextureExt: IsA<Texture> + 'static {
    // Provided methods
    fn color_state(&self) -> ColorState { ... }
    fn format(&self) -> MemoryFormat { ... }
    fn height(&self) -> i32 { ... }
    fn width(&self) -> i32 { ... }
    fn save_to_png(&self, filename: impl AsRef<Path>) -> Result<(), BoolError> { ... }
    fn save_to_png_bytes(&self) -> Bytes { ... }
    fn save_to_tiff(&self, filename: impl AsRef<Path>) -> Result<(), BoolError> { ... }
    fn save_to_tiff_bytes(&self) -> Bytes { ... }
}
Expand description

Trait containing all Texture methods.

§Implementors

DmabufTexture, GLTexture, MemoryTexture, Texture

Provided Methods§

Source

fn color_state(&self) -> ColorState

Available on crate feature v4_16 only.

Returns the color state associated with the texture.

§Returns

the color state of the Texture

Source

fn format(&self) -> MemoryFormat

Available on crate feature v4_10 only.

Gets the memory format most closely associated with the data of the texture.

Note that it may not be an exact match for texture data stored on the GPU or with compression.

The format can give an indication about the bit depth and opacity of the texture and is useful to determine the best format for downloading the texture.

§Returns

the preferred format for the texture’s data

Source

fn height(&self) -> i32

Returns the height of the @self, in pixels.

§Returns

the height of the Texture

Source

fn width(&self) -> i32

Returns the width of @self, in pixels.

§Returns

the width of the Texture

Source

fn save_to_png(&self, filename: impl AsRef<Path>) -> Result<(), BoolError>

Store the given @self to the @filename as a PNG file.

This is a utility function intended for debugging and testing. If you want more control over formats, proper error handling or want to store to a gio::File or other location, you might want to use save_to_png_bytes() or look into the gdk-pixbuf library.

§filename

the filename to store to

§Returns

true if saving succeeded, false on failure.

Source

fn save_to_png_bytes(&self) -> Bytes

Available on crate feature v4_6 only.

Store the given @self in memory as a PNG file.

Use Texture::from_bytes() to read it back.

If you want to serialize a texture, this is a convenient and portable way to do that.

If you need more control over the generated image, such as attaching metadata, you should look into an image handling library such as the gdk-pixbuf library.

If you are dealing with high dynamic range float data, you might also want to consider save_to_tiff_bytes() instead.

§Returns

a newly allocated GBytes containing PNG data

Source

fn save_to_tiff(&self, filename: impl AsRef<Path>) -> Result<(), BoolError>

Available on crate feature v4_6 only.

Store the given @self to the @filename as a TIFF file.

GTK will attempt to store data without loss.

§filename

the filename to store to

§Returns

true if saving succeeded, false on failure.

Source

fn save_to_tiff_bytes(&self) -> Bytes

Available on crate feature v4_6 only.

Store the given @self in memory as a TIFF file.

Use Texture::from_bytes() to read it back.

This function is intended to store a representation of the texture’s data that is as accurate as possible. This is particularly relevant when working with high dynamic range images and floating-point texture data.

If that is not your concern and you are interested in a smaller size and a more portable format, you might want to use save_to_png_bytes().

§Returns

a newly allocated GBytes containing TIFF data

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§