class_imagetexture.rst 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/ImageTexture.xml.
  6. .. _class_ImageTexture:
  7. ImageTexture
  8. ============
  9. **Inherits:** :ref:`Texture2D<class_Texture2D>` **<** :ref:`Texture<class_Texture>` **<** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. A :ref:`Texture2D<class_Texture2D>` based on an :ref:`Image<class_Image>`.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. 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:
  15. ::
  16. var image = Image.load_from_file("res://icon.svg")
  17. var texture = ImageTexture.create_from_image(image)
  18. $Sprite2D.texture = texture
  19. This way, textures can be created at run-time by loading images both from within the editor and externally.
  20. \ **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:
  21. ::
  22. var texture = load("res://icon.svg")
  23. $Sprite2D.texture = texture
  24. 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.
  25. \ **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:
  26. ::
  27. var texture = load("res://icon.svg")
  28. var image: Image = texture.get_image()
  29. 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>`.
  30. \ **Note:** The maximum texture size is 16384×16384 pixels due to graphics hardware limitations.
  31. .. rst-class:: classref-introduction-group
  32. Tutorials
  33. ---------
  34. - :doc:`Importing images <../tutorials/assets_pipeline/importing_images>`
  35. .. rst-class:: classref-reftable-group
  36. Properties
  37. ----------
  38. .. table::
  39. :widths: auto
  40. +-------------------------+-------------------------+----------------------------------------------------------------------------------------+
  41. | :ref:`bool<class_bool>` | resource_local_to_scene | ``false`` (overrides :ref:`Resource<class_Resource_property_resource_local_to_scene>`) |
  42. +-------------------------+-------------------------+----------------------------------------------------------------------------------------+
  43. .. rst-class:: classref-reftable-group
  44. Methods
  45. -------
  46. .. table::
  47. :widths: auto
  48. +-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`ImageTexture<class_ImageTexture>` | :ref:`create_from_image<class_ImageTexture_method_create_from_image>` **(** :ref:`Image<class_Image>` image **)** |static| |
  50. +-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`Format<enum_Image_Format>` | :ref:`get_format<class_ImageTexture_method_get_format>` **(** **)** |const| |
  52. +-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------+
  53. | void | :ref:`set_image<class_ImageTexture_method_set_image>` **(** :ref:`Image<class_Image>` image **)** |
  54. +-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`set_size_override<class_ImageTexture_method_set_size_override>` **(** :ref:`Vector2i<class_Vector2i>` size **)** |
  56. +-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------+
  57. | void | :ref:`update<class_ImageTexture_method_update>` **(** :ref:`Image<class_Image>` image **)** |
  58. +-----------------------------------------+----------------------------------------------------------------------------------------------------------------------------+
  59. .. rst-class:: classref-section-separator
  60. ----
  61. .. rst-class:: classref-descriptions-group
  62. Method Descriptions
  63. -------------------
  64. .. _class_ImageTexture_method_create_from_image:
  65. .. rst-class:: classref-method
  66. :ref:`ImageTexture<class_ImageTexture>` **create_from_image** **(** :ref:`Image<class_Image>` image **)** |static|
  67. Creates a new **ImageTexture** and initializes it by allocating and setting the data from an :ref:`Image<class_Image>`.
  68. .. rst-class:: classref-item-separator
  69. ----
  70. .. _class_ImageTexture_method_get_format:
  71. .. rst-class:: classref-method
  72. :ref:`Format<enum_Image_Format>` **get_format** **(** **)** |const|
  73. Returns the format of the texture, one of :ref:`Format<enum_Image_Format>`.
  74. .. rst-class:: classref-item-separator
  75. ----
  76. .. _class_ImageTexture_method_set_image:
  77. .. rst-class:: classref-method
  78. void **set_image** **(** :ref:`Image<class_Image>` image **)**
  79. Replaces the texture's data with a new :ref:`Image<class_Image>`. This will re-allocate new memory for the texture.
  80. 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.
  81. .. rst-class:: classref-item-separator
  82. ----
  83. .. _class_ImageTexture_method_set_size_override:
  84. .. rst-class:: classref-method
  85. void **set_size_override** **(** :ref:`Vector2i<class_Vector2i>` size **)**
  86. Resizes the texture to the specified dimensions.
  87. .. rst-class:: classref-item-separator
  88. ----
  89. .. _class_ImageTexture_method_update:
  90. .. rst-class:: classref-method
  91. void **update** **(** :ref:`Image<class_Image>` image **)**
  92. Replaces the texture's data with a new :ref:`Image<class_Image>`.
  93. \ **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.
  94. 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.
  95. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  96. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  97. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  98. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  99. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  100. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  101. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`