1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31:
| private void DrawBrush(Bitmap bmp, Point startPoint, Point endPoint, Color startColor, Color endColor) { float len = endPoint.X - startPoint.X;
float deltaRed = (endColor.R - startColor.R) / len; float deltaGreen = (endColor.G - startColor.G) / len; float deltaBlue = (endColor.B - startColor.B) / len;
float r = startColor.R, g = startColor.G, b = startColor.B;
for (int x = startPoint.X; x < endPoint.X; x++) { r += deltaRed; g += deltaGreen; b += deltaBlue;
for (int y = startPoint.Y; y < endPoint.Y; y++) { bmp.SetPixel(x, y, Color.FromArgb((int) r, (int) g, (int) b)); } } }
private void button1_Click(object sender, EventArgs e) { Bitmap img = new Bitmap(pictureBox1.Width, pictureBox1.Height); DrawBrush(img, new Point(0, 0), new Point(img.Width / 2, img.Height), Color.Red, Color.Green); DrawBrush(img, new Point(img.Width / 2, 0), new Point(img.Width, img.Height), Color.Green, Color.Blue); pictureBox1.Image = img; } |