Table of Contents

Class ImageTexture

Namespace
Godot
Assembly
GodotSharp.dll

A Texture2D based on an Image. For an image to be displayed, an ImageTexture has to be created from it using the CreateFromImage(Image) method:

var image = Image.load_from_file("res://icon.svg")
  var texture = ImageTexture.create_from_image(image)
  $Sprite2D.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 Load(string), as it may not work in exported projects:

var texture = load("res://icon.svg")
  $Sprite2D.texture = texture

This is because images have to be imported as a CompressedTexture2D 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.

Note: The image can be retrieved from an imported texture using the GetImage() method, which returns a copy of the image:

var texture = load("res://icon.svg")
  var image: Image = texture.get_image()

An 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.

public class ImageTexture : Texture2D, IDisposable
Inheritance
ImageTexture
Implements
Inherited Members

Constructors

ImageTexture()

public ImageTexture()

Methods

CreateFromImage(Image)

Creates a new ImageTexture and initializes it by allocating and setting the data from an Image.

public static ImageTexture CreateFromImage(Image image)

Parameters

image Image

Returns

ImageTexture

GetFormat()

Returns the format of the texture, one of Image.Format.

public Image.Format GetFormat()

Returns

Image.Format

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

SetImage(Image)

Replaces the texture's data with a new Image. This will re-allocate new memory for the texture.

If you want to update the image, but don't need to change its parameters (format, size), use Update(Image) instead for better performance.

public void SetImage(Image image)

Parameters

image Image

SetSizeOverride(Vector2I)

Resizes the texture to the specified dimensions.

public void SetSizeOverride(Vector2I size)

Parameters

size Vector2I

Update(Image)

Replaces the texture's data with a new Image.

Note: The texture has to be created using CreateFromImage(Image) or initialized first with the SetImage(Image) method before it can be updated. The new image dimensions, format, and mipmaps configuration should match the existing texture's image configuration.

Use this method over SetImage(Image) if you need to update the texture frequently, which is faster than allocating additional memory for a new texture each time.

public void Update(Image image)

Parameters

image Image