Skip to content

Format

typescript
Texture2D.GetPixel(x, y, mipLevel)

class: Texture2D

Description

Get the color of a specific pixel on a texture.

It can be used to read the color information of a specific pixel in a texture, allowing you to retrieve the pixel data of the texture at runtime.

Parameters

param_nametypedescription
xnumberThe x coordinate of the pixel to retrieve, starting from 0.
ynumberThe y coordinate of the pixel to retrieve, starting from 0.
mipLevelnumberThe mip level of the texture.

Return

typedescription
ColorThe color of the pixel.

Code Example

typescript
let uuid = "31A9092E126B4B19BBFD9D5FCD75AA49";
let tex = Resources.Load<Texture2D>(Texture2D, uuid);
if (tex == null) {
    throw new Exception("failed to load texture2d: " + uuid);
}
let color = tex.GetPixel(0, 0, 0);
Debug.Log("Pixel color at (0,0) is: ", color);