我的代码快完成了,但它不起作用。它给了我错误的图像位置,我认为这是因为图像设置为拉伸(stretch)。
有什么帮助吗?
private void originalmaster_Click(object sender, EventArgs e)
{
var rato = e as MouseEventArgs;
Bitmap b = new Bitmap(originalmaster.Image);
Color c = b.GetPixel(rato.X, rato.Y);
h = Math.Round(c.GetHue(), 0);
h = (h * 255) / 360;
s = Math.Round(c.GetSaturation() * 255, 0);
v = Math.Round(c.GetBrightness() * 255, 0);
lb_valores_hsv.Text = "H: " + h + " S: " + s + " V: " + v;
lb_valores_rgb.Text = "R: " + c.R + " G: " + c.G + " B: " + c.B;
}
rato 的位置不正确。
最佳答案
简短的回答:
MouseEventArgs rato = e as MouseEventArgs;
Bitmap b = ((Bitmap)originalmaster.Image);
int x = rato.X * b.Width / originalmaster.ClientSize.Width;
int y = rato.Y * b.Height / originalmaster.ClientSize.Height;
Color c = b.GetPixel(x, y);
关于C#鼠标获取Picturebox的颜色(基本完成),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41701829/