I'm trying to programmatically load an Image
and create an ImageTexture
from it. I want to do this so that I can programmatically modify the pixel data of the Image
. Here's some sample code from my TextureRect
:
func _ready():
var image_texture = ImageTexture.new()
image = Image.new()
image.load('res://path/to/file.png')
image.lock()
image_texture.create_from_image(image, 0)
self.texture = image_texture
This works fine when I run the game from the editor. However, I get a warning in the debugger that says "Loading resource as image file, this will not work on export." And thus, when I export to Android, these images are not loaded.
I do not want to use the load()
function (as suggested here), because that gives me a StreamTexture
and doesn't allow me to manipulate pixels.
I've found a few Github issues about this:
- https://github.com/godotengine/godot/issues/20972
- https://github.com/godotengine/godot/issues/18638
- https://github.com/godotengine/godot/issues/15380
but none of them seem to provide solutions for this issue.
So - is there a good way to make this work for exported games?