您好,我在内存中有 heightData,有时(当我编辑它时)我想将它保存为 jpg。这是我的代码:
float multi = 0.2f;
float[,] heightData = quadTree.HeightData;
Color[] heightMapColors = new Color[heightData.Length];
for (int x = 0; x < heightData.GetLength(0); x++)
{
for (int y = 0; y < heightData.GetLength(1); y++)
{
byte colorData = (byte)(heightData[x, y] / multi);
heightMapColors[x + y * heightData.GetLength(0)].R = colorData;
heightMapColors[x + y * heightData.GetLength(0)].G = colorData;
heightMapColors[x + y * heightData.GetLength(0)].B = colorData;
}
}
Texture2D heightMap = new Texture2D(device, heightData.GetLength(0), heightData.GetLength(1), false, SurfaceFormat.Color);
heightMap.SetData<Color>(heightMapColors);
using (System.IO.Stream stream = System.IO.File.OpenWrite(@"D:\test.jpg"))
{
heightMap.SaveAsJpeg(stream, heightData.GetLength(0), heightData.GetLength(1));
}
我 100% 确定我在 heightMapColors 中有数据,但保存的 jpg 只有黑色。:/这是一个好方法,还是有什么问题?