Not sure if you still need an answer but I had to do something similar and couldn't find anything helpful. Ended up with this:
var imageData: PoolByteArray
# Resize to required image size (* 4 as each float has 4 bytes)
imageData.resize(image_width * image_height * 4)
# Wrap 64-bit float into Vector2 to cast it to 32-bit
var valueVector: Vector2 = Vector2(value, 0.0)
# Convert Vector2 to bytes
var bytes: PoolByteArray = var2bytes(valueVector)
# Calculate position in image (* 4 as each float has 4 bytes)
var position: int = (y * image_width + x) * 4
# Read Vector.x float bytes (byte 4 to 7)
for i in range(4):
imageData[position + i] = bytes[i + 4]
var image: Image = Image.new()
image.create_from_data(image_width, image_height, false, Image.FORMAT_RF, imageData)
If you just append to the PoolByteArray this should work:
var valueVector: Vector2 = Vector2(value, 0.0)
var bytes: PoolByteArray = var2bytes(valueVector)
for i in range(4):
imageData.append(bytes[i + 4])
var image: Image = Image.new()
image.create_from_data(image_width, image_height, false, Image.FORMAT_RF, imageData)
Took me a while until I noticed that Godot uses 64-bit floats but the Images only support 32-bit floats.