WebcamTexture getPixels32

Hi,

I need the pixels of webcamtexture in a byte array. But somehow I receive strange data.
So i tried to populate an array like this:

data = new Color32[webcamTexture.width * webcamTexture.height];	
m_vidframe_byte = new Byte[webcamTexture.width * webcamTexture.height * 3];	
...
webcamTexture.GetPixels32(data);

for (int i = 0; i < data.Length; i++ )  {
	m_vidframe_byte[3 * i] = data[i].r;
	m_vidframe_byte[3 * i + 1] = data[i].g;
	m_vidframe_byte[3 * i + 2] = data[i].b;
}

Somehow, the data ist strange, so I try to output the dtaa as Image:

Color[] tmp = new Color[data.Length];
			for (int i = 0; i < tmp.Length; i++) {
				tmp[i].r = data[i].r;//m_vidframe_byte[3 * i];
				tmp[i].g = data[i].g;//m_vidframe_byte[3 * i + 1];
				tmp[i].b = data[i].b;//m_vidframe_byte[3 * i + 2];
			}
			
    		// For testing purposes, also write to a file in the project folder
			count++;
			
		    var tex = new Texture2D (640, 480, TextureFormat.RGB24, false);
		    tex.SetPixels(tmp);
		    tex.Apply();
		
		    // Encode texture into PNG
		    var bytes = tex.EncodeToPNG();
		    Destroy (tex);
	
			
    		File.WriteAllBytes(Application.dataPath + "/../SavedScreen" + count + ".png", bytes);

The image looks very strange. Chekcv attachment for it. What is the problem. I am on it since days.

So please help.

839349--31280--$SavedScreen99.png

Not sure if you still help on this one… adding just incase someone else comes across this thread.
m_vidframe_byte = new Byte[webcamTexture.width * webcamTexture.height * 3];
should be
m_vidframe_byte = new Byte[webcamTexture.width * webcamTexture.height * 4]; because the format is RBG32 and that’s 32 bits not 24 bits.

Then you will face an interestingly coloured texture. That’s because the format is actually BGR and not RGB in m_vidframe_byte:

for (int i = 0; i < data.Length; i++ ) {
m_vidframe_byte[3 * i] = data*.b; /////////// ← Note this is b and not r*
m_vidframe_byte[3 * i + 1] = data*.g;
m_vidframe_byte[3 * i + 2] = data.r;
_}*_

Hi
where do you write this for loop? Is it inside update function or start function?