using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Graphics G;
Pen P = new Pen(Color.Red, 2.0f);
Boolean state = false;
int x1, y1, x2, y2;
Bitmap Pict01 = new Bitmap("vector_cp1.png");
Bitmap Pict02 = new Bitmap(380,350);
Color tempColor;
private Color returnAvg4(Color a, Color b, Color c, Color d)
{
int A, R, B, G;
A = ((a.A + b.A + c.A + d.A) / 4);
B = ((a.B + b.B + c.B + d.B) / 4);
R = ((a.R + b.R + c.R + d.R) / 4);
G = ((a.G + b.G + c.G + d.G) / 4);
return Color.FromArgb(A, R, G, B);
}
public Form1()
{
InitializeComponent();
G = pictureBox1.CreateGraphics();
for (int j = 0; j < 350; j += 2)
for (int i = 0; i < 380; i += 2)
{
tempColor = returnAvg4(
Pict01.GetPixel(i, j),
Pict01.GetPixel(i + 1, j),
Pict01.GetPixel(i, j + 1),
Pict01.GetPixel(i + 1, j + 1)
);
Pict02.SetPixel(i, j, tempColor);
Pict02.SetPixel(i + 1, j, tempColor);
Pict02.SetPixel(i, j + 1, tempColor);
Pict02.SetPixel(i + 1, j + 1, tempColor);
}
}
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
if (state)
{
G.DrawLine(P, x1, y1, e.X, e.Y);
}
else
{
x1 = e.X;
y1 = e.Y;
}
state = !state;
}
private void button1_Click(object sender, EventArgs e)
{
G.Clear(Color.White);
G.DrawImage(Pict01, 0, 0);
}
private void button2_Click(object sender, EventArgs e)
{
G.Clear(Color.White);
G.DrawImage(Pict02, 0, 0);
}
}
}