【发布时间】:2021-10-01 10:16:56
【问题描述】:
我正在将 png 作为纹理加载:
byte[] bytes = File.ReadAllBytes(path);
Texture2D texture = new Texture2D(1, 1);
texture.LoadImage(bytes);
问题在于texture.GetPixel(23,23)检索到的像素
在调试中好像是白色的,调试日志:texture.GetPixel(23, 23) "RGBA(1.000, 1.000, 1.000, 0.000)" UnityEngine.Color
我不知道如何获得该像素的正确值。 我在这里放了带有纹理的照片,以及我从像素颜色中获得的图像
使用的代码:
public void JustTest()
{
ClearGrid();
byte[] bytes = File.ReadAllBytes(path);
Texture2D texture = new Texture2D(1, 1);
texture.LoadImage(bytes);
for (int i = 0; i <= texture.width; i++)
{
for (int j = 0; j <= texture.height; j++)
{
GameObject sa = Instantiate(_testTilePrefab, new Vector3(i, 0.2f, j), _testTilePrefab.transform.rotation);
sa.GetComponent<Renderer>().material.color = texture.GetPixel(i, j);
}
}
}
【问题讨论】:
标签: image unity3d png pixel texture2d