static void InitializeGradient(IRenderSurface display) { if (PreviousClientSize != display.Stride + display.Height) { PreviousClientSize = display.Stride + display.Height; PixelBuffer = new int[display.Height * display.Width]; Color[] gradient = ColorUtility.CreateGradient(display.Width, ColorSet); int[] initialLine = new int[display.Stride]; for (int index = 0; index < display.Stride; index++) { Color current = gradient[index]; initialLine[index] = BitConverter.ToInt32 ( new byte[] { current.B, current.G, current.R, 0 }, 0 ); } unsafe { for (int line = 0; line < display.Height; line++) { fixed(int *ptr = &PixelBuffer[display.Stride * line]) { Marshal.Copy(initialLine, 0, ( IntPtr )ptr, initialLine.Length); } } } } }