How to specify a backing storage format when loading an Image?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By sjml

Is there any way, when using the ResourceLoader to load an image directly (not going through a texture) to tell it up front that it should be stored as FORMAT_R8? I’m pulling in a pretty large image that only contains an alpha channel, and while I can convert it right after load, it feels like not the most efficient use of memory.

I haven’t used it much, but are you aware of the Image class?

Image — Godot Engine (stable) documentation in English

jgodfrey | 2020-11-29 20:54

Yes, that’s what I’m using to load it. But it doesn’t let me specify the format at load time.

sjml | 2020-11-29 20:55

(Currently messing with different file formats to see if I can get Godot to auto-detect what the file is.)

sjml | 2020-11-29 20:57

Ah, yeah, got it. Poking around, I wonder about…

  • Load the raw data via File.get_buffer() to load the data as a PoolByteArray
  • Create the image via Image.create_from_data() which accepts the data from a PoolByteArray and allows a format to be specified…

Though, I’ve never tried it…

jgodfrey | 2020-11-29 21:16