unity Texture2D 像素访问

unity像素级贴图

public Texture2D getTexture(float[] rgb)
    {
        Texture2D texture;
        int cnt = 0;
        for (int y = height - 1; y >= 0; y--)
        {
            for (int x = 0; x < width; x++)
            {
                color.r = rgb[cnt + 2] / 255.0f;
                color.g = rgb[cnt + 1] / 255.0f;
                color.b = rgb[cnt] / 255.0f;
                cnt += 3;
                texture.SetPixel(x, y, color);
            }
        }
        texture.Apply();
        return texture;
    }

gameObject.GetComponent<Renderer>().material.mainTexture = getTexture();

C# 路径

string path = System.IO.Path.GetFullPath(@"C:\Users\abc\Desktop\Unity")

猜你喜欢

转载自blog.csdn.net/smilife_/article/details/89358736