:right-sidebar: True Texture =================================================================== .. currentmodule:: gi.repository.Gdk .. class:: Texture(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` Subclasses: :class:`~gi.repository.Gdk.DmabufTexture`, :class:`~gi.repository.Gdk.GLTexture`, :class:`~gi.repository.Gdk.MemoryTexture` Implemented Interfaces: :class:`~gi.repository.Gdk.Paintable`, :class:`~gi.repository.Gio.Icon`, :class:`~gi.repository.Gio.LoadableIcon` ``GdkTexture`` is the basic element used to refer to pixel data. 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 :obj:`~gi.repository.GdkPixbuf.Pixbuf`, or from bytes stored in memory, a file, or a :obj:`~gi.repository.Gio.Resource`. The ownership of the pixel data is transferred to the ``GdkTexture`` instance; you can only make a copy of it, via :obj:`~gi.repository.Gdk.Texture.download`. ``GdkTexture`` is an immutable object: That means you cannot change anything about it other than increasing the reference count via :obj:`~gi.repository.GObject.Object.ref`, and consequently, it is a thread-safe object. Constructors ------------ .. rst-class:: interim-class .. class:: Texture :no-index: .. classmethod:: new_for_pixbuf(pixbuf: ~gi.repository.GdkPixbuf.Pixbuf) -> ~gi.repository.Gdk.Texture Creates a new texture object representing the ``GdkPixbuf``. This function is threadsafe, so that you can e.g. use GTask and :obj:`~gi.repository.Gio.Task.run_in_thread` to avoid blocking the main thread while loading a big image. :param pixbuf: a ``GdkPixbuf`` .. classmethod:: new_from_bytes(bytes: ~gi.repository.GLib.Bytes) -> ~gi.repository.Gdk.Texture 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 :const:`None` is returned, then ``error`` will be set. This function is threadsafe, so that you can e.g. use GTask and :obj:`~gi.repository.Gio.Task.run_in_thread` to avoid blocking the main thread while loading a big image. .. versionadded:: 4.6 :param bytes: a ``GBytes`` containing the data to load .. classmethod:: new_from_file(file: ~gi.repository.Gio.File) -> ~gi.repository.Gdk.Texture 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 :const:`None` is returned, then ``error`` will be set. This function is threadsafe, so that you can e.g. use GTask and :obj:`~gi.repository.Gio.Task.run_in_thread` to avoid blocking the main thread while loading a big image. :param file: ``GFile`` to load .. classmethod:: new_from_filename(path: str) -> ~gi.repository.Gdk.Texture 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 :const:`None` is returned, then ``error`` will be set. This function is threadsafe, so that you can e.g. use GTask and :obj:`~gi.repository.Gio.Task.run_in_thread` to avoid blocking the main thread while loading a big image. .. versionadded:: 4.6 :param path: the filename to load .. classmethod:: new_from_resource(resource_path: str) -> ~gi.repository.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 :obj:`~gi.repository.Gdk.Texture.new_from_file` to load it. This function is threadsafe, so that you can e.g. use GTask and :obj:`~gi.repository.Gio.Task.run_in_thread` to avoid blocking the main thread while loading a big image. :param resource_path: the path of the resource file Methods ------- .. rst-class:: interim-class .. class:: Texture :no-index: .. method:: download(data: ~typing.Sequence[int], stride: int) -> None 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: .. code-block:: :dedent: 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 :obj:`~gi.repository.Gdk.TextureDownloader`. :param data: pointer to enough memory to be filled with the downloaded data of ``texture`` :param stride: rowstride in bytes .. method:: get_format() -> ~gi.repository.Gdk.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. .. versionadded:: 4.10 .. method:: get_height() -> int Returns the height of the ``texture``, in pixels. .. method:: get_width() -> int Returns the width of ``texture``, in pixels. .. method:: save_to_png(filename: str) -> bool 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 :obj:`~gi.repository.Gio.File` or other location, you might want to use :obj:`~gi.repository.Gdk.Texture.save_to_png_bytes` or look into the gdk-pixbuf library. :param filename: the filename to store to .. method:: save_to_png_bytes() -> ~gi.repository.GLib.Bytes Store the given ``texture`` in memory as a PNG file. Use :obj:`~gi.repository.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 gdk-pixbuf library. If you are dealing with high dynamic range float data, you might also want to consider :obj:`~gi.repository.Gdk.Texture.save_to_tiff_bytes` instead. .. versionadded:: 4.6 .. method:: save_to_tiff(filename: str) -> bool Store the given ``texture`` to the ``filename`` as a TIFF file. GTK will attempt to store data without loss. .. versionadded:: 4.6 :param filename: the filename to store to .. method:: save_to_tiff_bytes() -> ~gi.repository.GLib.Bytes Store the given ``texture`` in memory as a TIFF file. Use :obj:`~gi.repository.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 :obj:`~gi.repository.Gdk.Texture.save_to_png_bytes`. .. versionadded:: 4.6 Properties ---------- .. rst-class:: interim-class .. class:: Texture :no-index: .. attribute:: props.height :type: int The height of the texture, in pixels. .. attribute:: props.width :type: int The width of the texture, in pixels.