arraysimage-processingarduinoserial-porttga

reconstructing a image from byte array in arduino


So I need to send screen captures from Unity to an Arduino. I have a communication line open where I can send X size of a byte array and receive them in the Arduino.
I have two questions:

What type of image (converted to byte[]) should I be sending to Arduino, I was thinking a tga type but I know Arduino (I am using a mega) has a very small ram and can struggle with this.

Second I don't know even where to start when it comes to reconstructing the image in the arduino. How do I go from an array of bytes to an image?

Any resources would be helpful, I just need somewhere to start.


Solution

  • You can use upng to decode png data on arduino. And in unity any texture can be encoded to png byte array with EncodeToPNG.

    https://github.com/elanthis/upng https://docs.unity3d.com/ScriptReference/ImageConversion.EncodeToPNG.html

    If transfer speed isn't an issue you can send each pixel in byte format. Use GetPixels32() to get an array of colours in byte format (0-255), 4 bytes per pixel (RGBA).

    Assuming you want to display the image on an LCD you can use Adafruit_GFX library to display a raw byte array to the LCD. http://learn.adafruit.com/adafruit-gfx-graphics-library