public static byte[] GeneratePreviewImage(float[,] Array, int GroundType) { var width = Array.GetLength(1); var height = Array.GetLength(0); var bitmap = new Bitmap(width, height); for (var y = 0; y < height; y++) { for (var x = 0; x < width; x++) { var HeightValue = (int)(Array[x, y] * 256); var color = TileColorSelector.SelectTileColor(HeightValue, GroundType); bitmap.SetPixel(x, y, color); } } Image image = bitmap; byte[] imageBytes; var memoryStream = new MemoryStream(); image.Save(memoryStream, ImageFormat.Png); imageBytes = memoryStream.ToArray(); return(imageBytes); }
public IActionResult Index() { mapRepository.GetMap(TempData.Peek("SelectedMap").ToString(), User.Identity.Name); var map = mapRepository.Map; var FloatArray = new float[map.Size, map.Size]; FloatArray = PerlinNoiseGenerator.GenerateMap(map.Size, map.Seed); if (map.MapType == 1) { FloatArray = IslandMaskGenerator.ApplyIslandMask(map.Size, FloatArray); } var IntegerArray = new int[map.Size, map.Size]; for (var y = 0; y < map.Size; y++) { for (var x = 0; x < map.Size; x++) { IntegerArray[x, y] = (int)(FloatArray[x, y] * 256); } } var width = map.Size; var height = map.Size; var ColorArray = new Color[map.Size, map.Size]; for (var y = 0; y < height; y++) { for (var x = 0; x < width; x++) { var HeightValue = IntegerArray[x, y]; var color = TileColorSelector.SelectTileColor(HeightValue, map.GroundType); ColorArray[x, y] = color; } } var model = new WorldMapViewModel { MapName = map.Name, Size = map.Size, HeightValues = IntegerArray, TileSize = 40, TileColors = ColorArray }; return(View(model)); }