/// <summary> /// Renders the terrain into an image. /// </summary> /// <param name="terrain">The terrain.</param> /// <returns>The rendered image.</returns> public static Image <Rgba32> ToImage(this GameMapTerrain terrain) { var bitmap = new Image <Rgba32>(0x100, 0x100); for (int y = 0; y < 0x100; y++) { for (int x = 0; x < 0x100; x++) { var color = Rgba32.Black; if (terrain.SafezoneMap[y, x]) { color = Rgba32.Gray; } else if (terrain.WalkMap[y, x]) { color = Rgba32.SpringGreen; } else { // we use the default color. } bitmap[x, y] = color; } } return(bitmap); }
private Stream RenderMap(IGameMapInfo map) { var terrain = new GameMapTerrain(map.MapName, map.TerrainData); using (var bitmap = new Image <Rgba32>(0x100, 0x100)) { for (int y = 0; y < 0x100; y++) { for (int x = 0; x < 0x100; x++) { var color = Rgba32.Black; if (terrain.SafezoneMap[y, x]) { color = Rgba32.Gray; } else if (terrain.WalkMap[y, x]) { color = Rgba32.SpringGreen; } else { // we use the default color. } bitmap[x, y] = color; } } var memoryStream = new MemoryStream(); bitmap.SaveAsPng(memoryStream); memoryStream.Position = 0; return(memoryStream); } }
private Stream RenderMap(IGameMapInfo map) { var terrain = new GameMapTerrain(map.MapName, map.TerrainData); using var bitmap = terrain.ToImage(); var memoryStream = new MemoryStream(); bitmap.SaveAsPng(memoryStream); memoryStream.Position = 0; return(memoryStream); }
private Response RenderMap(dynamic parameters) { var gameServer = this.servers.OfType <IGameServer>().FirstOrDefault(s => s.Id == (byte)parameters.serverId); var map = gameServer?.ServerInfo.Maps.FirstOrDefault(m => m.MapNumber == (short)parameters.mapId); if (map == null) { Log.Warn($"requested map not available. map number: {parameters.mapId}; server id: {parameters.serverId}"); return(null); } var terrain = new GameMapTerrain(map.MapName, map.TerrainData); using (var bitmap = new SkiaSharp.SKBitmap(0x100, 0x100)) { for (int y = 0; y < 0x100; y++) { for (int x = 0; x < 0x100; x++) { var color = SKColors.Black; if (terrain.SafezoneMap[y, x]) { color = SKColors.Gray; } else if (terrain.WalkMap[y, x]) { color = SKColors.SpringGreen; } bitmap.SetPixel(x, y, color); } } using (var memoryStream = new SKDynamicMemoryWStream()) { if (SKPixmap.Encode(memoryStream, bitmap, SKEncodedImageFormat.Png, 100)) { return(this.Response.FromStream(memoryStream.DetachAsData().AsStream, "image/png")); } } return(null); } }
private Response RenderMap(dynamic parameters) { var gameServer = this.servers.OfType <IGameServer>().FirstOrDefault(s => s.Id == (byte)parameters.serverId); var map = gameServer?.ServerInfo.Maps.FirstOrDefault(m => m.Map.Number == (short)parameters.mapId); if (map == null) { Log.Warn($"requested map not available. map number: {parameters.mapId}; server id: {parameters.serverId}"); return(null); } var terrain = new GameMapTerrain(map.Map); using (var bitmap = new Bitmap(0x100, 0x100, PixelFormat.Format32bppArgb)) { for (int y = 0; y < 0x100; y++) { for (int x = 0; x < 0x100; x++) { Color color = Color.FromArgb(unchecked ((int)0xFF000000)); if (terrain.SafezoneMap[y, x]) { color = Color.FromArgb(unchecked ((int)0xFF808080)); } else if (terrain.WalkMap[y, x]) { color = Color.FromArgb(unchecked ((int)0xFF00FF7F)); } bitmap.SetPixel(x, y, color); } } var memoryStream = new MemoryStream(); bitmap.Save(memoryStream, ImageFormat.Png); memoryStream.Position = 0; var response = this.Response.FromStream(memoryStream, "image/png"); return(response); } }
private Stream RenderMap(IGameMapInfo map) { var terrain = new GameMapTerrain(map.MapName, map.TerrainData); using (var bitmap = new SkiaSharp.SKBitmap(0x100, 0x100)) { for (int y = 0; y < 0x100; y++) { for (int x = 0; x < 0x100; x++) { var color = SKColors.Black; if (terrain.SafezoneMap[y, x]) { color = SKColors.Gray; } else if (terrain.WalkMap[y, x]) { color = SKColors.SpringGreen; } else { // we use the default color. } bitmap.SetPixel(x, y, color); } } using (var memoryStream = new SKDynamicMemoryWStream()) { if (SKPixmap.Encode(memoryStream, bitmap, SKEncodedImageFormat.Png, 100)) { return(memoryStream.DetachAsData().AsStream()); } } return(null); } }