实现效果:
知识运用:
Color对象的RGB属性
实现代码:
private void button1_Click(object sender, EventArgs e) { OpenFileDialog open = new OpenFileDialog(); open.Filter = "*.jpg,*.jpeg,*.bmp,*.png,*.tif,*.wmf|*.jpg;*.jpeg;*.bmp;*.png;*.tif;*.wmf"; open.ShowDialog(); Image image = System.Drawing.Image.FromFile(open.FileName); pictureBox1.Image = image; } private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { Bitmap bitmap = (Bitmap)pictureBox1.Image; try { Color color = bitmap.GetPixel(e.X,e.Y); textBox1.Text = color.R.ToString(); textBox2.Text = color.G.ToString(); textBox3.Text = color.B.ToString(); } catch {} }