Version: 2021.3
public Color32[] GetPixels32 (Color32[] colors= null);

参数

colors 用于接收像素数据的可选数组。

返回

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. } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961