public static Color[] GradientColors(Color startColor, Color endColor, int count) { count = Math.Max(count, 2); Bitmap image = new Bitmap(1024, 3); Graphics g = image.Graphics(); Brush br = new LinearGradientBrush(image.Bounds(), startColor, endColor, 0.0F); g.FillRectangle(br, image.Bounds()); br.Dispose(); g.Dispose(); Color[] colors = new Color[count]; colors[0] = startColor; colors[count - 1] = endColor; if (count > 2) { FastBitmap fb = new FastBitmap(image); fb.Lock(); for (int i = 1; i < count - 1; i++) { colors[i] = fb.GetPixel(image.Width * i / (count - 1), 1); } fb.Unlock(); fb.Dispose(); } image.Dispose(); return(colors); }
/// <summary> /// Locks this bitmap into memory and returns a FastBitmap that can be used to manipulate its pixels /// </summary> /// <param name="bitmap">The bitmap to lock</param> /// <param name="lockFormat">The underlying pixel format to use when locking the bitmap</param> /// <returns>A locked FastBitmap</returns> public static FastBitmap FastLock(this Bitmap bitmap, FastBitmapLockFormat lockFormat) { var fast = new FastBitmap(bitmap); fast.Lock(lockFormat); return(fast); }
/// <summary> /// Locks this bitmap into memory and returns a FastBitmap that can be used to manipulate its pixels /// </summary> /// <param name="bitmap">The bitmap to lock</param> /// <returns>A locked FastBitmap</returns> public static FastBitmap FastLock(this Bitmap bitmap) { var fast = new FastBitmap(bitmap); fast.Lock(); return(fast); }