Class: Gdk::Texture

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

Direct Known Subclasses

DmabufTexture, GLTexture, MemoryTexture

Instance Method Summary collapse

Constructor Details

#initialize(resource_path) ⇒ Gdk::Texture

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

The file format is detected automatically. The supported formats
are PNG and JPEG, though more formats might be available.

It is a fatal error if resource_path does not specify a valid
image resource and the program will abort if that happens.
If you are unsure about the validity of a resource, use
[ctorGdk.Texture.new_from_file] to load it.

This function is threadsafe, so that you can e.g. use GTask
and [methodGio.Task.run_in_thread] to avoid blocking the main thread
while loading a big image.

Parameters:

  • resource_path (String)

    the path of the resource file

Instance Method Details

#download(data, stride) ⇒ nil

Downloads the texture into local memory.

This may be an expensive operation, as the actual texture data
may reside on a GPU or on a remote display server.

The data format of the downloaded data is equivalent to
%CAIRO_FORMAT_ARGB32, so every downloaded pixel requires
4 bytes of memory.

Downloading a texture into a Cairo image surface:

surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                      gdk_texture_get_width (texture),
                                      gdk_texture_get_height (texture));
gdk_texture_download (texture,
                      cairo_image_surface_get_data (surface),
                      cairo_image_surface_get_stride (surface));
cairo_surface_mark_dirty (surface);

For more flexible download capabilities, see
[structGdk.TextureDownloader].

Parameters:

  • data (Array<Integer>)

    pointer to enough memory to be filled with the
    downloaded data of texture

  • stride (Integer)

    rowstride in bytes

Returns:

  • (nil)

#formatGdk::MemoryFormat

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:

#heightInteger

The height of the texture, in pixels.

Returns:

  • (Integer)

    height

#height=(height) ⇒ Integer

The height of the texture, in pixels.

Parameters:

  • height (Integer)

Returns:

  • (Integer)

    height

  • (Integer)

    height

#save_to_png(filename) ⇒ Boolean

Store the given texture 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 [ifaceGio.File] or other location, you might want to
use [methodGdk.Texture.save_to_png_bytes] or look into the
gdk-pixbuf library.

Parameters:

  • filename (Gdk::filename)

    the filename to store to

Returns:

  • (Boolean)

    true if saving succeeded, false on failure.

#save_to_png_bytesGLib::Bytes

Store the given texture in memory as a PNG file.

Use [ctorGdk.Texture.new_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 [methodGdk.Texture.save_to_tiff_bytes]
instead.

Returns:

  • (GLib::Bytes)

    a newly allocated GBytes containing PNG data

#save_to_tiff(filename) ⇒ Boolean

Store the given texture to the filename as a TIFF file.

GTK will attempt to store data without loss.

Parameters:

  • filename (Gdk::filename)

    the filename to store to

Returns:

  • (Boolean)

    true if saving succeeded, false on failure.

#save_to_tiff_bytesGLib::Bytes

Store the given texture in memory as a TIFF file.

Use [ctorGdk.Texture.new_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 [methodGdk.Texture.save_to_png_bytes].

Returns:

  • (GLib::Bytes)

    a newly allocated GBytes containing TIFF data

#widthInteger

The width of the texture, in pixels.

Returns:

  • (Integer)

    width

#width=(width) ⇒ Integer

The width of the texture, in pixels.

Parameters:

  • width (Integer)

Returns:

  • (Integer)

    width

  • (Integer)

    width