conversion between Color32[] and byte[] fast

I have a unity script in c# and a dll file written in c++, and I need to capture the live video from the web camera and use the video in both unity and dll. So now I have two options: 1) capture the video in unity by using WebCamTexture, and pass the data into the function in dll; or 2) capture the video using opencv in dll, and pass the data into unity, and convert it to Color32.

Could anybody tell me how to
(1) convert from Color32 to byte, pass to dll, and convert the received byte to a valid image format(eg. IplImage in OpenCV)?
(2) convert the image captured in dll to byte, pass it to unity, and interpret it as Color32,

AS FAST AS POSSIBLE please?

Thank you and wait for your suggestions!

Sounds like you need to understand your image format better. Colour32 already is made of bytes - its Red, Green, Blue, and Alpha properties (r,g,b,a respectively) are all in byte format, that’s the point of Colour32 over Colour. Sounds like you just need to serialise them in an order that your target format understands.