Struct gdnative_bindings_lily::Image [−][src]
pub struct Image { /* fields omitted */ }
Expand description
core class Image
inherits Resource
(reference counted).
Official documentation
See the documentation of this class in the Godot engine’s official documentation. The method descriptions are generated from it and typically contain code samples in GDScript, not Rust.
Memory management
The lifetime of this object is automatically managed through reference counting.
Class hierarchy
Image inherits methods from:
Safety
All types in the Godot API have “interior mutability” in Rust parlance.
To enforce that the official thread-safety guidelines are
followed, the typestate pattern is used in the Ref
and TRef
smart pointers,
and the Instance
API. The typestate Access
in these types tracks whether the
access is unique, shared, or exclusive to the current thread. For more information,
see the type-level documentation on Ref
.
Implementations
Constants
Creates a new instance of this object.
This is a reference-counted type. The returned object is automatically managed
by Ref
.
Alpha-blends src_rect
from src
image to this image at coordinates dest
.
Alpha-blends src_rect
from src
image to this image using mask
image at coordinates dst
. Alpha channels are required for both src
and mask
. dst
pixels and src
pixels will blend if the corresponding mask pixel’s alpha value is not 0. src
image and mask
image must have the same size (width and height) but they can have different formats.
Copies src_rect
from src
image to this image at coordinates dst
.
Blits src_rect
area from src
image to this image at the coordinates given by dst
. src
pixel is copied onto dst
if the corresponding mask
pixel’s alpha value is not 0. src
image and mask
image must have the same size (width and height) but they can have different formats.
Converts a bumpmap to a normalmap. A bumpmap provides a height offset per-pixel, while a normalmap provides a normal direction per pixel.
Default Arguments
bump_scale
-1.0
Removes the image’s mipmaps.
Compresses the image to use less memory. Can not directly access pixel data while the image is compressed. Returns error if the chosen compression mode is not available. See [enum CompressMode] and [enum CompressSource] constants.
Creates an empty image of given size and format. See [enum Format] constants. If use_mipmaps
is true
then generate mipmaps for this image. See the [method generate_mipmaps].
Creates a new image of given size and format. See [enum Format] constants. Fills the image with the given raw data. If use_mipmaps
is true
then loads mipmaps for this image from data
. See [method generate_mipmaps].
Crops the image to the given width
and height
. If the specified size is larger than the current size, the extra area is filled with black pixels.
Decompresses the image if it is compressed. Returns an error if decompress function is not available.
Returns [constant ALPHA_BLEND] if the image has data for alpha values. Returns [constant ALPHA_BIT] if all the alpha values are stored in a single bit. Returns [constant ALPHA_NONE] if no data for alpha values is found.
Stretches the image and enlarges it by a factor of 2. No interpolation is done.
Blends low-alpha pixels with nearby pixels.
Generates mipmaps for the image. Mipmaps are pre-calculated and lower resolution copies of the image. Mipmaps are automatically used if the image needs to be scaled down when rendered. This improves image quality and the performance of the rendering. Returns an error if the image is compressed, in a custom format or if the image’s width/height is 0.
Default Arguments
renormalize
-false
Returns the image’s format. See [enum Format] constants.
Returns the image’s height.
Returns the offset where the image’s mipmap with index mipmap
is stored in the data
dictionary.
Returns the color of the pixel at (x, y)
if the image is locked. If the image is unlocked, it always returns a Color with the value (0, 0, 0, 1.0)
. This is the same as [method get_pixelv], but two integer arguments instead of a Vector2 argument.
Returns the color of the pixel at src
if the image is locked. If the image is unlocked, it always returns a Color with the value (0, 0, 0, 1.0)
. This is the same as [method get_pixel], but with a Vector2 argument instead of two integer arguments.
Returns a new image that is a copy of the image’s area specified with rect
.
Returns a Rect2 enclosing the visible portion of the image, considering each pixel with a non-zero alpha channel as visible.
Returns true
if the image has generated mipmaps.
Returns true
if the image is compressed.
Returns true
if all the image’s pixels have an alpha value of 0. Returns false
if any pixel has an alpha value higher than 0.
Loads an image from file path
. See [url=https://docs.godotengine.org/en/latest/getting_started/workflow/assets/importing_images.html#supported-image-formats]Supported image formats[/url] for a list of supported image formats and limitations.
Loads an image from the binary contents of a JPEG file.
Loads an image from the binary contents of a PNG file.
Loads an image from the binary contents of a TGA file.
Loads an image from the binary contents of a WebP file.
Locks the data for reading and writing access. Sends an error to the console if the image is not locked when reading or writing a pixel.
Converts the image’s data to represent coordinates on a 3D plane. This is used when the image represents a normalmap. A normalmap can add lots of detail to a 3D surface without increasing the polygon count.
Multiplies color values with alpha values. Resulting color values for a pixel are (color * alpha)/256
.
Resizes the image to the given width
and height
. New pixels are calculated using interpolation
. See interpolation
constants.
Default Arguments
interpolation
-1
Resizes the image to the nearest power of 2 for the width and height. If square
is true
then set width and height to be the same.
Default Arguments
square
-false
Converts a standard RGBE (Red Green Blue Exponent) image to an sRGB image.
Saves the image as an EXR file to path
. If grayscale
is true
and the image has only one channel, it will be saved explicitly as monochrome rather than one red channel. This function will return [constant ERR_UNAVAILABLE] if Godot was compiled without the TinyEXR module.
Default Arguments
grayscale
-false
Saves the image as a PNG file to path
.
Sample code is GDScript unless otherwise noted.
Sets the Color of the pixel at (x, y)
if the image is locked. Example:
var img = Image.new()
img.create(img_width, img_height, false, Image.FORMAT_RGBA8)
img.lock()
img.set_pixel(x, y, color) # Works
img.unlock()
img.set_pixel(x, y, color) # Does not have an effect
Sample code is GDScript unless otherwise noted.
Sets the Color of the pixel at (dst.x, dst.y)
if the image is locked. Note that the dst
values must be integers. Example:
var img = Image.new()
img.create(img_width, img_height, false, Image.FORMAT_RGBA8)
img.lock()
img.set_pixelv(Vector2(x, y), color) # Works
img.unlock()
img.set_pixelv(Vector2(x, y), color) # Does not have an effect
Converts the raw data from the sRGB colorspace to a linear scale.
Methods from Deref<Target = Resource>
Duplicates the resource, returning a new resource. By default, sub-resources are shared between resource copies for efficiency. This can be changed by passing true
to the subresources
argument which will copy the subresources.
Note: If subresources
is true
, this method will only perform a shallow copy. Nested resources within subresources will not be duplicated and will still be shared.
Default Arguments
subresources
-false
If [member resource_local_to_scene] is enabled and the resource was loaded from a PackedScene instantiation, returns the local scene where this resource’s unique copy is in use. Otherwise, returns null
.
The name of the resource. This is an optional identifier.
The path to the resource. In case it has its own file, it will return its filepath. If it’s tied to the scene, it will return the scene’s path, followed by the resource’s index.
If true
, the resource will be made unique in each instance of its local scene. It can thus be modified in a scene instance without impacting other instances of that same scene.
If true
, the resource will be made unique in each instance of its local scene. It can thus be modified in a scene instance without impacting other instances of that same scene.
The name of the resource. This is an optional identifier.
The path to the resource. In case it has its own file, it will return its filepath. If it’s tied to the scene, it will return the scene’s path, followed by the resource’s index.
This method is called when a resource with [member resource_local_to_scene] enabled is loaded from a PackedScene instantiation. Its behavior can be customized by overriding [method _setup_local_to_scene] from script. For most resources, this method performs no base logic. ViewportTexture performs custom logic to properly set the proxy texture and flags in the local viewport.
Sets the path of the resource, potentially overriding an existing cache entry for this path. This differs from setting [member resource_path], as the latter would error out if another resource was already cached for the given path.
Trait Implementations
type RefKind = RefCounted
type RefKind = RefCounted
Creates an explicitly null reference of Self
as a method argument. This makes type
inference easier for the compiler compared to Option
. Read more
Creates a new instance of Self
using a zero-argument constructor, as a Unique
reference. Read more
Performs a dynamic reference downcast to target type. Read more
Performs a static reference upcast to a supertype that is guaranteed to be valid. Read more
Creates a persistent reference to the same Godot object with shared thread access. Read more
unsafe fn assume_thread_local(&self) -> Ref<Self, ThreadLocal> where
Self: GodotObject<RefKind = RefCounted>,
unsafe fn assume_thread_local(&self) -> Ref<Self, ThreadLocal> where
Self: GodotObject<RefKind = RefCounted>,
Creates a persistent reference to the same Godot object with thread-local thread access. Read more
Creates a persistent reference to the same Godot object with unique access. Read more
Recovers a instance ID previously returned by Object::get_instance_id
if the object is
still alive. See also TRef::try_from_instance_id
. Read more
Auto Trait Implementations
impl RefUnwindSafe for Image
impl UnwindSafe for Image