Texture2D.GetPixels32
Declaration
public Color32[] GetPixels32(int miplevel = 0);Параметры
| Параметр | Описание |
|---|---|
| мипуровень | Уровень mipmap для получения. Диапазон 0 через текстуру Texture.mipmapCount. Значение по умолчанию 0. |
Возвращаемое значение
Color32[] Массив, содержащий цвета пикселей.
Описание
Получает данные цвета пикселей для уровня mipmap как структуры Color32.
Этот метод получает данные пикселей из текстуры в памяти CPU. Texture.isReadable должно быть true.
Массив содержит пиксели строка за строкой, начиная с нижней левой части текстуры. Размер массива равен ширине × высоте уровня mipmap.
Каждый пиксель является Color32 struct. GetPixels32 может быть медленнее, чем некоторые другие методы текстуры, потому что он преобразует формат текстуры использует в Color32. Чтобы получить данные пикселей быстрее, используйте GetPixelData вместо этого.
Единый призыв к GetPixels32 обычно быстрее, чем несколько вызовов GetPixel, особенно для больших текстур.
Если GetPixels32 не удаётся, Unity вызывает исключение. GetPixels32 может завершиться неудачей, если массив содержит слишком много данных. GetPixelData или GetRawTextureData вместо очень больших текстур.
using UnityEngine;
public class Texture2DExample : MonoBehaviour { public Texture2D source; public Texture2D destination;
void Start() { // Get a copy of the color data from the source Texture2D, in lower-precision int format. // Each element in the array represents the color data for an individual pixel. int sourceMipLevel = 0; Color32[] pixels = source.GetPixels32(sourceMipLevel);
// If required, manipulate the pixels before applying them to the destination Texture2D. // This example code reverses the array, which rotates the image 180 degrees. System.Array.Reverse(pixels, 0, pixels.Length);
// Set the pixels of the destination Texture2D. int destinationMipLevel = 0; destination.SetPixels32(pixels, destinationMipLevel);
// Apply changes to the destination Texture2D, which uploads its data to the GPU. destination.Apply(); } }
Дополнительные ресурсы: ,SetPixels,, ,GetPixelData,, ,mipmapCount,.