public void SetColourData(Color[,] colours) { if (colours == null) { throw new ArgumentNullException(nameof(colours)); } if ((colours.GetLowerBound(0) != 0) || (colours.GetLowerBound(0) >= Width) || (colours.GetLowerBound(1) != 0) || (colours.GetLowerBound(1) >= Height)) { throw new ArgumentOutOfRangeException(nameof(colours)); } var imageData = _context.GetImageData(0, 0, Width, Height); var data = imageData.Data; for (var x = 0; x < Width; x++) { for (var y = 0; y < Height; y++) { var colour = colours[x, y]; var startIndex = (y * (Width * 4)) + (x * 4); data[startIndex] = colour.R; data[startIndex + 1] = colour.G; data[startIndex + 2] = colour.B; data[startIndex + 3] = 255; // alpha } } _context.PutImageData(imageData, 0, 0); }
private static void changeColorAt(int x, int y, Color colour) { if (x > imageArray.GetUpperBound(0) || x < imageArray.GetLowerBound(0) || y > imageArray.GetUpperBound(1) || y < imageArray.GetLowerBound(1)) { Console.WriteLine("Exception: changeColorAt: outOfBounds: {0}, {1}", x, y); return; } imageArray[x, y] = colour; }