I have been working on webcam streaming for video and photo capture on Android devices within Unity3D. Most of the examples I have found in order to capture webcam feeds use a specific WebCamTexture object in order to get access to the devices camera hardware. I currently am able to capture the camera input but the WebCamTexture stores the data as a Color32[]. I found this solution below for converting a Color32[] to a byte[] but it seems to be swapping the red and blue color channels.
https://stackoverflow.com/a/21575147/8115962
Is there a way to prevent the red and blue channels from being reversed?
Here is another way to Convert
Color32
array fromWebCamTexture
to byte array:First, create a structure to hold the converted array:
The
WebCamTexture
to convert:Create new instance of that structure:
Initialize Color32 with the appropriate size:
Fill
Color32
which automatically fills byte array:Now, you can use
colorArray.byteArray
which is byte array.Load into Texture 2D if needed:
Like I said in my comment, it's better to convert the
WebCamTexture
toTexture2D
then to jpeg or png then send it over the network. That will reduce the size of the image. See this answer for more information.