123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- :github_url: hide
- .. DO NOT EDIT THIS FILE!!!
- .. Generated automatically from Godot engine sources.
- .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
- .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/ImageTexture.xml.
- .. _class_ImageTexture:
- ImageTexture
- ============
- **Inherits:** :ref:`Texture2D<class_Texture2D>` **<** :ref:`Texture<class_Texture>` **<** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
- A :ref:`Texture2D<class_Texture2D>` based on an :ref:`Image<class_Image>`.
- .. rst-class:: classref-introduction-group
- Description
- -----------
- A :ref:`Texture2D<class_Texture2D>` based on an :ref:`Image<class_Image>`. For an image to be displayed, an **ImageTexture** has to be created from it using the :ref:`create_from_image<class_ImageTexture_method_create_from_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 :ref:`@GDScript.load<class_@GDScript_method_load>` over loading them from within the filesystem dynamically with :ref:`Image.load<class_Image_method_load>`, 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 :ref:`CompressedTexture2D<class_CompressedTexture2D>` first to be loaded with :ref:`@GDScript.load<class_@GDScript_method_load>`. If you'd still like to load an image file just like any other :ref:`Resource<class_Resource>`, import it as an :ref:`Image<class_Image>` resource instead, and then load it normally using the :ref:`@GDScript.load<class_@GDScript_method_load>` method.
- \ **Note:** The image can be retrieved from an imported texture using the :ref:`Texture2D.get_image<class_Texture2D_method_get_image>` 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 :ref:`EditorImportPlugin<class_EditorImportPlugin>`.
- \ **Note:** The maximum texture size is 16384×16384 pixels due to graphics hardware limitations.
- .. rst-class:: classref-introduction-group
- Tutorials
- ---------
- - :doc:`Importing images <../tutorials/assets_pipeline/importing_images>`
- .. rst-class:: classref-reftable-group
- Properties
- ----------
- .. table::
- :widths: auto
- +-------------------------+-------------------------+----------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | resource_local_to_scene | ``false`` (overrides :ref:`Resource<class_Resource_property_resource_local_to_scene>`) |
- +-------------------------+-------------------------+----------------------------------------------------------------------------------------+
- .. rst-class:: classref-reftable-group
- Methods
- -------
- .. table::
- :widths: auto
- +-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------+
- | :ref:`ImageTexture<class_ImageTexture>` | :ref:`create_from_image<class_ImageTexture_method_create_from_image>` **(** :ref:`Image<class_Image>` image **)** |static| |
- +-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Format<enum_Image_Format>` | :ref:`get_format<class_ImageTexture_method_get_format>` **(** **)** |const| |
- +-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`set_image<class_ImageTexture_method_set_image>` **(** :ref:`Image<class_Image>` image **)** |
- +-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`set_size_override<class_ImageTexture_method_set_size_override>` **(** :ref:`Vector2i<class_Vector2i>` size **)** |
- +-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`update<class_ImageTexture_method_update>` **(** :ref:`Image<class_Image>` image **)** |
- +-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------+
- .. rst-class:: classref-section-separator
- ----
- .. rst-class:: classref-descriptions-group
- Method Descriptions
- -------------------
- .. _class_ImageTexture_method_create_from_image:
- .. rst-class:: classref-method
- :ref:`ImageTexture<class_ImageTexture>` **create_from_image** **(** :ref:`Image<class_Image>` image **)** |static|
- Creates a new **ImageTexture** and initializes it by allocating and setting the data from an :ref:`Image<class_Image>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_ImageTexture_method_get_format:
- .. rst-class:: classref-method
- :ref:`Format<enum_Image_Format>` **get_format** **(** **)** |const|
- Returns the format of the texture, one of :ref:`Format<enum_Image_Format>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_ImageTexture_method_set_image:
- .. rst-class:: classref-method
- void **set_image** **(** :ref:`Image<class_Image>` image **)**
- Replaces the texture's data with a new :ref:`Image<class_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 :ref:`update<class_ImageTexture_method_update>` instead for better performance.
- .. rst-class:: classref-item-separator
- ----
- .. _class_ImageTexture_method_set_size_override:
- .. rst-class:: classref-method
- void **set_size_override** **(** :ref:`Vector2i<class_Vector2i>` size **)**
- Resizes the texture to the specified dimensions.
- .. rst-class:: classref-item-separator
- ----
- .. _class_ImageTexture_method_update:
- .. rst-class:: classref-method
- void **update** **(** :ref:`Image<class_Image>` image **)**
- Replaces the texture's data with a new :ref:`Image<class_Image>`.
- \ **Note:** The texture has to be created using :ref:`create_from_image<class_ImageTexture_method_create_from_image>` or initialized first with the :ref:`set_image<class_ImageTexture_method_set_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 :ref:`set_image<class_ImageTexture_method_set_image>` if you need to update the texture frequently, which is faster than allocating additional memory for a new texture each time.
- .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
- .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
- .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
- .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
- .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
- .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
- .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
|