ImageTexture
Inherits: Texture < Resource < Reference < Object Texture based on an Image.
Description
Texture based on an Image. For an image to be displayed, an ImageTexture has to be created from it using the create_from_image method:
var texture = ImageTexture.new()var image = Image.new()image.load("res://icon.png")texture.create_from_image(image)$Sprite.texture = texture
This way, textures can be created at run-time by loading images both from within the editor and externally. Warning: Prefer to load imported textures with @GDScript.load over loading them from within the filesystem dynamically with Image.load, as it may not work in exported projects:
var texture = load("res://icon.png")$Sprite.texture = texture
StreamTexture first to be loaded with @GDScript.load. If you’d still like to load an image file just like any other Resource, import it as an Image resource instead, and then load it normally using the @GDScript.load method. Texture.get_data method, which returns a copy of the data:
var texture = load("res://icon.png")var image : Image = texture.get_data()
ImageTexture is not meant to be operated from within the editor interface directly, and is mostly useful for rendering images on screen dynamically via code. If you need to generate images procedurally from within the editor, consider saving and importing images as custom texture resources implementing a new EditorImportPlugin.
Note: The maximum texture size is 16384×16384 pixels due to graphics hardware limitations.
Tutorials
- Importing images
Properties
Methods
Enumerations
Storage: - STORAGE_RAW = 0 —- Image data is stored raw and unaltered.
- STORAGE_COMPRESS_LOSSY = 1 —- Image data is compressed with a lossy algorithm. You can set the storage quality with lossy_quality.
- STORAGE_COMPRESS_LOSSLESS = 2 —- Image data is compressed with a lossless algorithm.
Property Descriptions
- float lossy_quality STORAGE_COMPRESS_LOSSY.
- Storage storage
The storage type (raw, lossy, or compressed).
Method Descriptions
- create ( int width, int height, Format format, int flags=7 )
ImageTexturewithwidthandheight.formatis a value from Format,flagsis any combination of Flags.
- create_from_image ( Image image, int flags=7 )
Image with
flagsfrom Flags. An sRGB to linear color space conversion can take place, according to Format.
- Format get_format ( ) const Format.
- Error load ( String path ) Loads an image from a file path and creates a texture from it. Note: This method is deprecated and will be removed in Godot 4.0, use Image.load and create_from_image instead.
- set_data ( Image image ) Image. Note: The texture has to be initialized first with the create_from_image method before it can be updated. The new image dimensions, format, and mipmaps configuration should match the existing texture’s image configuration, otherwise it has to be re-created with the create_from_image method. create_from_image if you need to update the texture frequently, which is faster than allocating additional memory for a new texture each time.
- set_size_override ( Vector2 size ) Resizes the texture to the specified dimensions.
