In my current project, my game has a websocket server that provides data to a python client. This data is used by different machine learning agents that then send different acctions back to the game to play.

I am now working on a feature for the server to provide screenshots of the game to the client (to use as input for neural networks). I know how to get a screenshot but I would like the server to send the image data to the client over websocket.

For this I have tried to send the data in different ways but I am not able to reconstruct the image in python.

In my function I have the following to get the Image object: var image = get_viewport().get_texture().get_data() image.flip_y()

I've tried sending the data in raw, base64 and hex but no progress. Any suggestion/idea? I think one of the problems is that I am not understanding the PoolByteArray object.

22 days later

I'm having a similar issue in dealing with PoolByteArrays but I could probably offer some insight in how the raw image data is stored in it.

The PoolByteArray store data as four 4 byte sets per pixel in the RGBA color format. Which each element in the array would represent a RGB color channel or alpha. For example if you had a semi transparent red square that was 32*32. The raw data would read.

0 = 255 # Red
1 = 0	#Green
2 = 0	#Blue
3 = 128 #Alpha
4 = 255
5 = 0
6 = 0
7 = 128
# etc

And the array size would be 32234.

you may want to look into StreamPeer you can send it a PoolByteArray using .put_data() and convert it to various others.

@"Xero Wolf" said: I'm having a similar issue in dealing with PoolByteArrays but I could probably offer some insight in how the raw image data is stored in it.

The PoolByteArray store data as four 4 byte sets per pixel in the RGBA color format. Which each element in the array would represent a RGB color channel or alpha. For example if you had a semi transparent red square that was 32*32. The raw data would read.

0 = 255 # Red
1 = 0	#Green
2 = 0	#Blue
3 = 128 #Alpha
4 = 255
5 = 0
6 = 0
7 = 128
# etc

And the array size would be 32234.

you may want to look into StreamPeer you can send it a PoolByteArray using .put_data() and convert it to various others.

This helps a lot. For now I have implemented a function to transform the Image into a binary matrix. But with this I think I can improve the next time I refactor the code.

Thank you !!!

2 years later