public HeatMap() { Points = new List <PointWithValue>(); Limits = new HeatMapLimits { xMin = 0, xMax = 0, yMin = 0, yMax = 0 }; SetDefaultColors(); }
public Bitmap Draw() { Bitmap result = new Bitmap(Width, Height); if (Limits.xMax == 0 && Limits.xMin == 0 && Limits.yMax == 0 && Limits.yMin == 0) { this.Limits = new HeatMapLimits { xMin = 0, xMax = Width, yMin = 0, yMax = Height }; } var pointsWithDistance = new List <PointWithDistance>(Points.Count); for (var i = 0; i < Points.Count; i++) { pointsWithDistance.Add(new PointWithDistance()); } int x = Limits.xMin; int y = Limits.yMin; int w = Width; int wy = w * y; int pointsLimit = Points.Count; int xStart = Limits.xMin; int xEnd = Limits.xMax; int yEnd = Limits.yMax; bool isEmpty = true; while (y < yEnd) { var val = GetPointValue(pointsLimit, new PointWithValue() { X = x, Y = y }, pointsWithDistance); if (val != -255) { isEmpty = false; int imgX = x - Limits.xMin; int imgY = y - Limits.yMin; if (imgX < Width && imgY < Height && imgX >= 0 && imgY >= 0) { var col = GetRGBColor(val); var imgCol = Color.FromArgb(col.A, col.R, col.G, col.B); result.SetPixel(imgX, imgY, imgCol); } } x = x + 1; if (x > xEnd) { x = xStart; y = y + 1; wy = w * y; } } if (isEmpty) { return(null); } return(result); }