Add static methods for creating Image and ImageTexture

This commit is contained in:
kobewi 2022-05-04 01:49:20 +02:00
parent ca18a02e00
commit d2900429e8
42 changed files with 117 additions and 243 deletions

View file

@ -106,8 +106,7 @@
if error != OK:
push_error("Couldn't load the image.")
var texture = ImageTexture.new()
texture.create_from_image(image)
var texture = ImageTexture.create_from_image(image)
# Display the image in a TextureRect node.
var texture_rect = TextureRect.new()

View file

@ -308,6 +308,13 @@
[b]Note:[/b] Godot's BMP module doesn't support 16-bit per pixel images. Only 1-bit, 4-bit, 8-bit, 24-bit, and 32-bit per pixel images are supported.
</description>
</method>
<method name="load_from_file" qualifiers="static">
<return type="Image" />
<argument index="0" name="path" type="String" />
<description>
Creates a new [Image] and loads data from the specified file.
</description>
</method>
<method name="load_jpg_from_buffer">
<return type="int" enum="Error" />
<argument index="0" name="buffer" type="PackedByteArray" />

View file

@ -6,10 +6,8 @@
<description>
A [Texture2D] based on an [Image]. For an image to be displayed, an [ImageTexture] has to be created from it using the [method create_from_image] method:
[codeblock]
var texture = ImageTexture.new()
var image = Image.new()
image.load("res://icon.png")
texture.create_from_image(image)
var image = Image.load_from_file("res://icon.png")
var texture = ImageTexture.create_from_image(image)
$Sprite2D.texture = texture
[/codeblock]
This way, textures can be created at run-time by loading images both from within the editor and externally.
@ -31,11 +29,11 @@
<link title="Importing images">$DOCS_URL/tutorials/assets_pipeline/importing_images.html</link>
</tutorials>
<methods>
<method name="create_from_image">
<return type="void" />
<method name="create_from_image" qualifiers="static">
<return type="ImageTexture" />
<argument index="0" name="image" type="Image" />
<description>
Initializes the texture by allocating and setting the data from an [Image].
Creates a new [ImageTexture] and initializes it by allocating and setting the data from an [Image].
</description>
</method>
<method name="get_format" qualifiers="const">