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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| Point clientPoint;
int x;
int y;
Color c;
private void Form1_Load(object sender, EventArgs e)
{
pbImage.Image = new Bitmap("final.png");
pbImage.SizeMode = PictureBoxSizeMode.Zoom;
pbTest.Image = new Bitmap("final.png");
pbTest.SizeMode = PictureBoxSizeMode.Zoom;
pbTest.Paint += new System.Windows.Forms.PaintEventHandler(this.pbTest_Paint);
this.Controls.Add(pbTest);
}
private void pbTest_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
\\création d'un rectangle bleu\\
Graphics g = e.Graphics;
SolidBrush myBrush = new SolidBrush(Color.FromArgb(255, 0, 0, 127));
Point point1 = new Point(63, 35);
Point point2 = new Point(94, 33);
Point point3 = new Point(94, 98);
Point point4 = new Point(61, 104);
Point[] curvePoints = { point1, point2, point3, point4 };
g.FillPolygon(myBrush, curvePoints);
}
private void pbImage_Click(object sender, EventArgs e)
{
\\ enregistrement des cordonnées du curseur\\
x = Cursor.Position.X;
y = Cursor.Position.Y;
clientPoint = this.PointToClient(new Point(x, y));
x = clientPoint.X;
y = clientPoint.Y;
\\ enregistrement de la couleur du pixel\\
Bitmap bmTest = new Bitmap(pbTest.Image);
c = bmTest.GetPixel(x, y);
\\affichage des coordonnées du curseur et de la couleur du pixel\\
lblPos.Text = "x= " + x.ToString() + " y= " + y.ToString() + "c=" + c.B.ToString();
} |
Partager