protected void DrawMap(MagickImage image, int[,] geog, int[] borders = null) { using (IPixelCollection pixels = image.GetPixels()) { if (borders != null) { for (int x = borders[0]; x < borders[2]; x++) { for (int y = borders[1]; y < borders[3]; y++) { MagickColor col; float val = (float)geog[x, y] / 100f; byte bval = (byte)(val * 255); if (bval < sealevel) { col = MapColours.mapWaterColours[WaterColours.HeightsWater]; } else { col = MagickColor.FromRgb(bval, bval, bval); } pixels.ModifyPixel(x, y, col); } } } else if (borders == null) { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { MagickColor col; float val = (float)geog[x, y] / 100f; byte bval = (byte)(val * 255); if (bval < sealevel) { col = MapColours.mapWaterColours[WaterColours.HeightsWater]; } else { col = MagickColor.FromRgb(bval, bval, bval); } pixels.ModifyPixel(x, y, col); } } } } UpdateImage(image); }
protected void PaintPixel(HashSet <VoronoiPoint> pixels, MagickImage map, Region[] regList) { using (IPixelCollection pix = map.GetPixels()) { foreach (var pixel in pixels) { MagickColor col; if (pixel.value == -1) { col = MapColours.mapWaterColours[WaterColours.RegionWater]; } else if (pixel.value == -2) { col = MagickColor.FromRgb(0, 0, 0); } else { col = MagickColor.FromRgb((byte)regList[pixel.value].rgb[0], (byte)regList[pixel.value].rgb[1], (byte)regList[pixel.value].rgb[2]); } this.map.mapTiles[pixel.x, pixel.y].region = pixel.value; pix.ModifyPixel(pixel.x, pixel.y, col); } } UpdateImage(this.map.mapRegions); }
public static MagickImage ToImage(this float[,] data) { MagickImage mi = new MagickImage(MagickColor.FromRgb(0, 0, 0), data.GetLength(0), data.GetLength(1)); float min, max; data.MinMax(out min, out max); using (IPixelCollection pi = mi.GetPixels()) { for (int y = 0; y < mi.Height; y++) { for (int x = 0; x < mi.Width; x++) { float norm = 0; byte bnorm = 0; if (data[x, y] != 0) { norm = (data[x, y].NormaliseToRange(min, max)); bnorm = (byte)(norm * 255); } pi.ModifyPixel(x, y, MagickColor.FromRgb(bnorm, bnorm, bnorm)); } } } return(mi); }
protected void DrawPixels(MagickImage image, HashSet <int[]> pixelsCoords, int[,] geog) { using (IPixelCollection pixels = image.GetPixels()) { foreach (var p in pixelsCoords) { MagickColor col; float val = (float)geog[p[0], p[1]] / 100f; byte bval = (byte)(val * 255); if (bval < sealevel) { col = MapColours.mapWaterColours[WaterColours.HeightsWater]; } else { col = MagickColor.FromRgb(bval, bval, bval); } this.map.mapTiles[p[0], p[1]].height = bval; pixels.ModifyPixel(p[0], p[1], col); } } UpdateImage(image); }