Class: Gdk::Texture
- Inherits:
-
Object
- Object
- Gdk::Texture
- Defined in:
- (unknown)
Direct Known Subclasses
Instance Method Summary collapse
-
#download(data, stride) ⇒ nil
Downloads the texture into local memory.
-
#format ⇒ Gdk::MemoryFormat
Gets the memory format most closely associated with the data of the texture.
-
#height ⇒ Integer
The height of the texture, in pixels.
-
#height=(height) ⇒ Integer
The height of the texture, in pixels.
-
#initialize(resource_path) ⇒ Gdk::Texture
constructor
Creates a new texture by loading an image from a resource.
-
#save_to_png(filename) ⇒ Boolean
Store the given texture to the filename as a PNG file.
-
#save_to_png_bytes ⇒ GLib::Bytes
Store the given texture in memory as a PNG file.
-
#save_to_tiff(filename) ⇒ Boolean
Store the given texture to the filename as a TIFF file.
-
#save_to_tiff_bytes ⇒ GLib::Bytes
Store the given texture in memory as a TIFF file.
-
#width ⇒ Integer
The width of the texture, in pixels.
-
#width=(width) ⇒ Integer
The width of the texture, in pixels.
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.
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].
#format ⇒ 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.
#height ⇒ Integer
The height of the texture, in pixels.
#height=(height) ⇒ Integer
The height of the texture, in pixels.
#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.
#save_to_png_bytes ⇒ GLib::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.
#save_to_tiff(filename) ⇒ Boolean
Store the given texture to the filename as a TIFF file.
GTK will attempt to store data without loss.
#save_to_tiff_bytes ⇒ GLib::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].
#width ⇒ Integer
The width of the texture, in pixels.
#width=(width) ⇒ Integer
The width of the texture, in pixels.