Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: TextureCtors

[250:14] static extends: object

Alternate constructors for Texture. Usage: TextureCtors.<name>(...). The primary constructor lives directly on Texture.

Methods

  • newFromBytes (object bytes)

    Creates a new texture by loading an image from memory, The file format is detected automatically. The supported formats are PNG, JPEG and TIFF, though more formats might be available. If NULL is returned, then

    • @error will be set. This function is threadsafe, so that you can e.g. use GTask and [method@Gio.Task.run_in_thread] to avoid blocking the main thread while loading a big image. ::: warning Note that this function should not be used with untrusted data. Use a proper image loading framework such as libglycin, which can load many image formats into a GdkTexture.
    • @p bytes is a GBytes containing the data to load.
    • @r A new Texture.
  • newFromFile (object file)

    Creates a new texture by loading an image from a file. The file format is detected automatically. The supported formats are PNG, JPEG and TIFF, though more formats might be available. If NULL is returned, then

    • @error will be set. This function is threadsafe, so that you can e.g. use GTask and [method@Gio.Task.run_in_thread] to avoid blocking the main thread while loading a big image. ::: warning Note that this function should not be used with untrusted data. Use a proper image loading framework such as libglycin, which can load many image formats into a GdkTexture.
    • @p file is GFile to load.
    • @r A new Texture.
  • newFromFilename (string path)

    Creates a new texture by loading an image from a file. The file format is detected automatically. The supported formats are PNG, JPEG and TIFF, though more formats might be available. If NULL is returned, then

    • @error will be set. This function is threadsafe, so that you can e.g. use GTask and [method@Gio.Task.run_in_thread] to avoid blocking the main thread while loading a big image. ::: warning Note that this function should not be used with untrusted data. Use a proper image loading framework such as libglycin, which can load many image formats into a GdkTexture.
    • @p path is the filename to load.
    • @r A new Texture.
  • newFromResource (string resource_path)

    Creates a new texture by loading an image from a resource. The file format is detected automatically. The supported formats are PNG, JPEG and TIFF, 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 [ctor@Gdk.Texture.new_from_file] to load it. This function is threadsafe, so that you can e.g. use GTask and [method@Gio.Task.run_in_thread] to avoid blocking the main thread while loading a big image.
    • @p resource_path is the path of the resource file.
    • @r A new Texture.

class: TextureMeta

[336:14] static extends: object

Generated metadata helpers for Texture class surfaces.

Methods

  • properties ()

    Returns property metadata for Texture.

    • @r A list.

class: Texture

[29:7] extends: object

Refers to pixel data in various forms. It is primarily meant for pixel data that will not change over multiple frames, and will be used for a long time. There are various ways to create GdkTexture objects from a [class@GdkPixbuf.Pixbuf], or from bytes stored in memory, a file, or a [struct@Gio.Resource]. The ownership of the pixel data is transferred to the GdkTexture instance; you can only make a copy of it, via [method@Gdk.Texture.download]. GdkTexture is an immutable object: That means you cannot change anything about it other than increasing the reference count via [method@GObject.Object.ref], and consequently, it is a threadsafe object. GDK provides a number of threadsafe texture loading functions: [ctor@Gdk.Texture.new_from_resource], [ctor@Gdk.Texture.new_from_bytes], [ctor@Gdk.Texture.new_from_file], [ctor@Gdk.Texture.new_from_filename], [ctor@Gdk.Texture.new_for_pixbuf]. Note that these are meant for loading icons and resources that are shipped with the toolkit or application. It is recommended that you use a dedicated image loading framework such as glycin, if you need to load untrusted image data.

Members

  • handleObj
  • lib
  • retainedCallbacks
  • signalHandlerNames
  • signalSetterHandlers

Methods

  • Texture (pixbuf = null)

    Creates a new texture object representing the GdkPixbuf. This function is threadsafe, so that you can e.g. use GTask and [method@Gio.Task.run_in_thread] to avoid blocking the main thread while loading a big image.

    • @p pixbuf is a GdkPixbuf.
  • toNativeHandle (Source)

    Normalizes a constructor argument into a raw pointer carrier. Accepts a raw NativeHandle, a raw NativeBuffer returned from fn.call(...), another generated wrapper exposing handle(), or null. Returns null when the argument carries no pointer.

    • @p Source is the raw handle, raw buffer, wrapper, or null.
    • @r A raw pointer carrier or null when no pointer is present.
  • getLib ()

    Returns the opened native library for this generated wrapper.

    • @r The opened native library.
  • handle ()

    Returns the wrapped NativeHandle.

    • @r The wrapped NativeHandle.
  • isNull ()

    Returns true when the wrapped handle is null.

    • @r A bool.
  • describe ()

    Returns a small string for debugging generated wrappers.

    • @r A string.
  • asObject ()

    Wraps this handle as Object.

    • @r A Object object.
  • asPaintable ()

    Wraps this handle as Paintable.

    • @r A Paintable object.
  • asIcon ()

    Wraps this handle as Icon.

    • @r A Icon object.
  • asLoadableIcon ()

    Wraps this handle as LoadableIcon.

    • @r A LoadableIcon object.
  • get_color_state ()

    Returns the color state associated with the texture.

  • get_format ()

    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.

  • get_height ()

    Returns the height of the @texture, in pixels.

  • get_width ()

    Returns the width of @texture, in pixels.

  • save_to_png (string filename)

    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 [iface@Gio.File] or other location, you might want to use [method@Gdk.Texture.save_to_png_bytes] or look into the libglycin library.

    • @p filename is the filename to store to.
  • save_to_png_bytes ()

    Store the given @texture in memory as a PNG file. Use [ctor@Gdk.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 libglycin library. If you are dealing with high dynamic range float data, you might also want to consider [method@Gdk.Texture.save_to_tiff_bytes] instead.

  • save_to_tiff (string filename)

    Store the given @texture to the @filename as a TIFF file. GTK will attempt to store data without loss.

    • @p filename is the filename to store to.
  • save_to_tiff_bytes ()

    Store the given @texture in memory as a TIFF file. Use [ctor@Gdk.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 [method@Gdk.Texture.save_to_png_bytes].