colors | Optional array to receive pixel data. |
Color32[] An array that contains a copy of the requested pixel colors, represented by Color32 structs.
Retrieves a copy of the the pixel color data. The colors are represented by Color32 structs.
A single call to this function is usually faster than multiple calls to GetPixel, especially for large textures. This function is faster than GetPixels and uses less memory because it does not perform integer-to-float conversions
The returned array is a flattened 2D array, where the data appears row by row: the pixels are laid out left to right, bottom to top. The dimensions of the array are width * height
of the texture.
You can optionally pass in an array of Color32 structs to avoid allocating new memory each frame. This can improve performance if you are continuously reading data from the camera. The array must be initialized to the dimensions width * height
of the texture. If you don't pass an array, Unity will allocate one and return it.
using UnityEngine;
public class Example : MonoBehaviour { WebCamTexture webcamTexture; Color32[] data;
void Start() { // Start web cam feed webcamTexture = new WebCamTexture(); webcamTexture.Play(); data = new Color32[webcamTexture.width * webcamTexture.height]; }
void Update() { webcamTexture.GetPixels32(data); // Do processing of data here. } }