Hello I have heightData in memory and sometimes (when I edit it) I wanna save it to jpg. This is my code:
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));
}
I am 100% sure that I have data in heightMapColors, but saved jpg is only black. :/ Is it a good way how to do it or something is wrong?
Alpha should not be zero
heightMapColors[x + y * heightData.GetLength(0)].R = colorData;
heightMapColors[x + y * heightData.GetLength(0)].G = colorData;
heightMapColors[x + y * heightData.GetLength(0)].B = colorData;
heightMapColors[x + y * heightData.GetLength(0)].A = 255;