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
|
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
g = Graphics.FromImage(bmp);
}
Bitmap img,bmp;
Graphics g;
Color noire = Color.Black;
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Title = "Choose a shape...";
openFileDialog1.DefaultExt = "jpg";
openFileDialog1.Filter = "Bitmap file (*.bmp)|*.bmp|Images file JPEG (*.jpg)|*.jpg";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
img = new Bitmap(openFileDialog1.FileName);
pictureBox1.Image = img;
g = Graphics.FromImage(bmp);
g.DrawImage(pictureBox1.Image, 0, 0);
}
}
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
Color cl = bmp.GetPixel(e.X, e.Y);
if (cl == noire)
{
MessageBox.Show("noire");
}
else
{
MessageBox.Show("blanc");
}
}
}
} |
Partager