Hey,
I want to display an image in unity that was sent over a socket from an android device as a byte array. The byte array is sent successfully (here is a sample one), but in unity it is just rendered as a solid grey image.
Here is the code used to generate the Bitmap (80x50) on Android (Java) and convert it to a byte array:
bmp = Bitmap.createBitmap(80, 50, Bitmap.Config.ARGB_8888); //changing of content of the bmp omitted
ByteBuffer byteBuffer = ByteBuffer.allocate(bmp.getByteCount());
bmp.copyPixelsToBuffer(byteBuffer);
byte[] array = byteBuffer.array();
In Unity the byte[ ] should then be converted back to an image and set as the sprite of a GameObject:
Texture2D bmp = new Texture2D(80, 50, TextureFormat.ARGB32, false);
bmp.LoadRawTextureData(socketsServer.imageByteArray);
Vector2 pivot = new Vector2(0.5f, 0.5f); //Texture2D to Sprite
Rect tRect = new Rect(0, 0, 80, 50);
Sprite newSprite = Sprite.Create(bmp, tRect, pivot);
gameObject.GetComponent<Image>().overrideSprite = newSprite;
However the Image is just a solid grey rectangle and not the image that was originally sent. (see attached Images)
Has anyone encountered a similar problem before?
Thank you very much
Julian
