Unity 6.3
0 онлайн 62 гостей 3 в системе
Вход

Texture2DArray.GetPixels32

Declaration

public Color32[] GetPixels32(int arrayElement, int miplevel);
public Color32[] GetPixels32(int arrayElement);

Параметры

Параметр Описание
arrayElement Сегмент массива, из которого будут считываться пиксельные данные.
мипуровень Уровень mipmap для получения. Диапазон 0 через текстуру Texture.mipmapCount. Значение по умолчанию 0.

Возвращаемое значение

Color32[] Массив, содержащий цвета пикселей.

Описание

Получает данные цвета пикселей для уровня mipmap слоя в виде структур Color32.

Этот метод получает данные пикселей из текстуры в памяти CPU. Texture.isReadable должно быть true.

Массив содержит пиксели строка за строкой, начиная с нижней левой части текстуры. Размер массива равен ширине × высоте уровня mipmap.

Каждый пиксель является Color32 struct. GetPixels32 может быть медленнее, чем некоторые другие методы текстуры, потому что он преобразует формат текстуры использует в Color32. Чтобы получить данные пикселей быстрее, используйте GetPixelData вместо этого.

Если GetPixels32 не удаётся, Unity вызывает исключение. GetPixels32 может завершиться неудачей, если массив содержит слишком много данных. GetPixelData вместо очень больших текстур.

using UnityEngine;

public class Texture2DArrayExample : MonoBehaviour { public Texture2DArray source; public Texture2DArray destination;

void Start() { // Get a copy of the color data from the source Texture2DArray, in lower-precision int format. // Each element in the array represents the color data for an individual pixel. int sourceSlice = 0; int sourceMipLevel = 0; Color32[] pixels = source.GetPixels32(sourceSlice, sourceMipLevel);

// If required, manipulate the pixels before applying them to the destination Texture2DArray. // 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 Texture2DArray. int destinationSlice = 0; int destinationMipLevel = 0; destination.SetPixels32(pixels, destinationSlice, destinationMipLevel);

// Apply changes to the destination Texture2DArray, which uploads its data to the GPU. destination.Apply(); } }

Дополнительные ресурсы: ,GetPixels,, ,GetPixelData,, ,SetPixels32,, ,Graphics.CopyTexture,.