Skip to content

格式

typescript
Texture2D.GetPixel(x, y, mipLevel)

所属类: Texture2D

描述

获取纹理上特定位置的像素颜色。

它可以用于读取纹理中特定像素的颜色信息,使您能够在运行时检索纹理的像素数据。

参数

参数名类型描述
xnumber待获取像素的x坐标,从0开始
ynumber待获取像素的y坐标,从0开始
mipLevelnumbermip贴图级别

返回值

类型描述
Color像素颜色

代码示例

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