格式
typescript
Texture2D.GetPixel(x, y, mipLevel)所属类: Texture2D
描述
获取纹理上特定位置的像素颜色。
它可以用于读取纹理中特定像素的颜色信息,使您能够在运行时检索纹理的像素数据。
参数
| 参数名 | 类型 | 描述 |
|---|---|---|
| x | number | 待获取像素的x坐标,从0开始 |
| y | number | 待获取像素的y坐标,从0开始 |
| mipLevel | number | mip贴图级别 |
返回值
| 类型 | 描述 |
|---|---|
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);