加载了一张大小为19M的8位深度的png图片,用下面两种方法,出现错误,有没有朋友提供下思路
方法1
private Texture2D SetImageToString_Temp(string imgPath)
{
FileStream fs = new FileStream(imgPath, FileMode.Open, FileAccess.Read);
fs.Seek(0, SeekOrigin.Begin);
byte[] imgByte = new byte[fs.Length];
fs.Read(imgByte, 0, imgByte.Length);
fs.Close();
fs.Dispose();
fs = null;
int width = 5472;
int height = 3648;
Texture2D texture = new Texture2D(width, height,TextureFormat.RGB24,false);
texture.LoadImage(imgByte);
texture.Apply();
return texture;
}
结果:图片为问号,加载失败
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/575964441866141.png)
#######方法二:
```c#
void ShowPicHandle(string picPatj)
{
byte[] b = File.ReadAllBytes(picPatj);
int width = 5472;
int height = 3648;
int division = 8; // 長寬各除以 division 倍。可以填入 : 2 4 8 16 的值。
Texture2D t = new Texture2D(width / division, height / division, TextureFormat.RGB24, false);
byte[] b2 = new byte[t.width * t.height * 4]; // 不知為啥要乘 4 ,理論上乘 3 就好..但會報錯
int i = 0; // i : Gr R B Gb
int k = 0; // k : R G B
int w = width * (division - 1); // 跳 w 行
for (int y = 0; y < height; y += division, i += w)
{
for (int x = 0; x < width; x += division, i += division, k += 3)
{
b2[k + 0] = b[i + 1]; // R
b2[k + 1] = b[i]; // Gr
b2[k + 2] = b[i + width]; // B
}
}
t.LoadRawTextureData(b2);
t.Apply();
RawImageShowImage.texture = t;
}
结果:按照这位思路,链接:https://blog.csdn.net/weixin_38884324/article/details/83796187,图片出现偏移,我不太理解他写的什么意思,有朋友教导下嘛
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/532302441866156.png)
```