class_imagetexture.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/ImageTexture.xml.
  6. .. _class_ImageTexture:
  7. ImageTexture
  8. ============
  9. **Inherits:** :ref:`Texture<class_Texture>` **<** :ref:`Resource<class_Resource>` **<** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  10. A :ref:`Texture<class_Texture>` based on an :ref:`Image<class_Image>`.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. A :ref:`Texture<class_Texture>` 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 texture = ImageTexture.new()
  17. var image = Image.new()
  18. image.load("res://icon.png")
  19. texture.create_from_image(image)
  20. $Sprite.texture = texture
  21. This way, textures can be created at run-time by loading images both from within the editor and externally.
  22. \ **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:
  23. ::
  24. var texture = load("res://icon.png")
  25. $Sprite.texture = texture
  26. This is because images have to be imported as :ref:`StreamTexture<class_StreamTexture>` 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.
  27. But do note that the image data can still be retrieved from an imported texture as well using the :ref:`Texture.get_data<class_Texture_method_get_data>` method, which returns a copy of the data:
  28. ::
  29. var texture = load("res://icon.png")
  30. var image : Image = texture.get_data()
  31. 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>`.
  32. \ **Note:** The maximum texture size is 16384×16384 pixels due to graphics hardware limitations.
  33. \ **Note:** Mipmap generation can fail with some graphics drivers (especially on Android), resulting in black textures. In these cases, consider either calling :ref:`Image.generate_mipmaps<class_Image_method_generate_mipmaps>`, or creating an **ImageTexture** without :ref:`Texture.FLAG_MIPMAPS<class_Texture_constant_FLAG_MIPMAPS>`.
  34. .. rst-class:: classref-introduction-group
  35. Tutorials
  36. ---------
  37. - :doc:`Importing images <../tutorials/assets_pipeline/importing_images>`
  38. .. rst-class:: classref-reftable-group
  39. Properties
  40. ----------
  41. .. table::
  42. :widths: auto
  43. +-------------------------------------------+-----------------------------------------------------------------+----------------------------------------------------------------+
  44. | :ref:`int<class_int>` | flags | ``7`` (overrides :ref:`Texture<class_Texture_property_flags>`) |
  45. +-------------------------------------------+-----------------------------------------------------------------+----------------------------------------------------------------+
  46. | :ref:`float<class_float>` | :ref:`lossy_quality<class_ImageTexture_property_lossy_quality>` | ``0.7`` |
  47. +-------------------------------------------+-----------------------------------------------------------------+----------------------------------------------------------------+
  48. | :ref:`Storage<enum_ImageTexture_Storage>` | :ref:`storage<class_ImageTexture_property_storage>` | ``0`` |
  49. +-------------------------------------------+-----------------------------------------------------------------+----------------------------------------------------------------+
  50. .. rst-class:: classref-reftable-group
  51. Methods
  52. -------
  53. .. table::
  54. :widths: auto
  55. +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | void | :ref:`create<class_ImageTexture_method_create>` **(** :ref:`int<class_int>` width, :ref:`int<class_int>` height, :ref:`Format<enum_Image_Format>` format, :ref:`int<class_int>` flags=7 **)** |
  57. +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | void | :ref:`create_from_image<class_ImageTexture_method_create_from_image>` **(** :ref:`Image<class_Image>` image, :ref:`int<class_int>` flags=7 **)** |
  59. +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`Format<enum_Image_Format>` | :ref:`get_format<class_ImageTexture_method_get_format>` **(** **)** |const| |
  61. +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`load<class_ImageTexture_method_load>` **(** :ref:`String<class_String>` path **)** |
  63. +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | void | :ref:`set_data<class_ImageTexture_method_set_data>` **(** :ref:`Image<class_Image>` image **)** |
  65. +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | void | :ref:`set_size_override<class_ImageTexture_method_set_size_override>` **(** :ref:`Vector2<class_Vector2>` size **)** |
  67. +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. .. rst-class:: classref-section-separator
  69. ----
  70. .. rst-class:: classref-descriptions-group
  71. Enumerations
  72. ------------
  73. .. _enum_ImageTexture_Storage:
  74. .. rst-class:: classref-enumeration
  75. enum **Storage**:
  76. .. _class_ImageTexture_constant_STORAGE_RAW:
  77. .. rst-class:: classref-enumeration-constant
  78. :ref:`Storage<enum_ImageTexture_Storage>` **STORAGE_RAW** = ``0``
  79. :ref:`Image<class_Image>` data is stored raw and unaltered.
  80. .. _class_ImageTexture_constant_STORAGE_COMPRESS_LOSSY:
  81. .. rst-class:: classref-enumeration-constant
  82. :ref:`Storage<enum_ImageTexture_Storage>` **STORAGE_COMPRESS_LOSSY** = ``1``
  83. :ref:`Image<class_Image>` data is compressed with a lossy algorithm. You can set the storage quality with :ref:`lossy_quality<class_ImageTexture_property_lossy_quality>`.
  84. .. _class_ImageTexture_constant_STORAGE_COMPRESS_LOSSLESS:
  85. .. rst-class:: classref-enumeration-constant
  86. :ref:`Storage<enum_ImageTexture_Storage>` **STORAGE_COMPRESS_LOSSLESS** = ``2``
  87. :ref:`Image<class_Image>` data is compressed with a lossless algorithm.
  88. .. rst-class:: classref-section-separator
  89. ----
  90. .. rst-class:: classref-descriptions-group
  91. Property Descriptions
  92. ---------------------
  93. .. _class_ImageTexture_property_lossy_quality:
  94. .. rst-class:: classref-property
  95. :ref:`float<class_float>` **lossy_quality** = ``0.7``
  96. .. rst-class:: classref-property-setget
  97. - void **set_lossy_storage_quality** **(** :ref:`float<class_float>` value **)**
  98. - :ref:`float<class_float>` **get_lossy_storage_quality** **(** **)**
  99. The storage quality for :ref:`STORAGE_COMPRESS_LOSSY<class_ImageTexture_constant_STORAGE_COMPRESS_LOSSY>`.
  100. .. rst-class:: classref-item-separator
  101. ----
  102. .. _class_ImageTexture_property_storage:
  103. .. rst-class:: classref-property
  104. :ref:`Storage<enum_ImageTexture_Storage>` **storage** = ``0``
  105. .. rst-class:: classref-property-setget
  106. - void **set_storage** **(** :ref:`Storage<enum_ImageTexture_Storage>` value **)**
  107. - :ref:`Storage<enum_ImageTexture_Storage>` **get_storage** **(** **)**
  108. The storage type (raw, lossy, or compressed).
  109. .. rst-class:: classref-section-separator
  110. ----
  111. .. rst-class:: classref-descriptions-group
  112. Method Descriptions
  113. -------------------
  114. .. _class_ImageTexture_method_create:
  115. .. rst-class:: classref-method
  116. void **create** **(** :ref:`int<class_int>` width, :ref:`int<class_int>` height, :ref:`Format<enum_Image_Format>` format, :ref:`int<class_int>` flags=7 **)**
  117. Create a new **ImageTexture** with ``width`` and ``height``.
  118. \ ``format`` is a value from :ref:`Format<enum_Image_Format>`, ``flags`` is any combination of :ref:`Flags<enum_Texture_Flags>`.
  119. .. rst-class:: classref-item-separator
  120. ----
  121. .. _class_ImageTexture_method_create_from_image:
  122. .. rst-class:: classref-method
  123. void **create_from_image** **(** :ref:`Image<class_Image>` image, :ref:`int<class_int>` flags=7 **)**
  124. Initializes the texture by allocating and setting the data from an :ref:`Image<class_Image>` with ``flags`` from :ref:`Flags<enum_Texture_Flags>`. An sRGB to linear color space conversion can take place, according to :ref:`Format<enum_Image_Format>`.
  125. .. rst-class:: classref-item-separator
  126. ----
  127. .. _class_ImageTexture_method_get_format:
  128. .. rst-class:: classref-method
  129. :ref:`Format<enum_Image_Format>` **get_format** **(** **)** |const|
  130. Returns the format of the texture, one of :ref:`Format<enum_Image_Format>`.
  131. .. rst-class:: classref-item-separator
  132. ----
  133. .. _class_ImageTexture_method_load:
  134. .. rst-class:: classref-method
  135. :ref:`Error<enum_@GlobalScope_Error>` **load** **(** :ref:`String<class_String>` path **)**
  136. Loads an image from a file path and creates a texture from it.
  137. \ **Note:** This method is deprecated and will be removed in Godot 4.0, use :ref:`Image.load<class_Image_method_load>` and :ref:`create_from_image<class_ImageTexture_method_create_from_image>` instead.
  138. .. rst-class:: classref-item-separator
  139. ----
  140. .. _class_ImageTexture_method_set_data:
  141. .. rst-class:: classref-method
  142. void **set_data** **(** :ref:`Image<class_Image>` image **)**
  143. Replaces the texture's data with a new :ref:`Image<class_Image>`.
  144. \ **Note:** The texture has to be initialized first with the :ref:`create_from_image<class_ImageTexture_method_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 :ref:`create_from_image<class_ImageTexture_method_create_from_image>` method.
  145. Use this method over :ref:`create_from_image<class_ImageTexture_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.
  146. .. rst-class:: classref-item-separator
  147. ----
  148. .. _class_ImageTexture_method_set_size_override:
  149. .. rst-class:: classref-method
  150. void **set_size_override** **(** :ref:`Vector2<class_Vector2>` size **)**
  151. Resizes the texture to the specified dimensions.
  152. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  153. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  154. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  155. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`