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.