我正在构建一个能够获取屏幕一部分像素的应用程序。我试图通过使表单的背景透明来做到这一点,以便您可以看穿表单。问题是,当我使用 PanelToBitmap 函数时,我得到的是透明颜色,而不是用户实际可见的像素。
目前我正在使用这个。
Point point = new Point();
if (point.X > this.Location.X && point.X < this.Location.X + this.Width && point.Y > this.Location.Y + RectangleToScreen(this.ClientRectangle).Top - this.Top && point.Y < this.Location.Y + this.Height)
{
point.X = point.X - this.Location.X;
point.Y = point.Y - this.Location.Y;
Bitmap img = (Bitmap)PanelToBitmap(this);
Color color = img.GetPixel(point.X, point.Y);
form.label1.Text = color.R.ToString();
form.label2.Text = color.G.ToString();
form.label3.Text = color.B.ToString();
}
是否有任何函数能够获取用户实际可见的像素?我在考虑 Gdi32 库中的 GetPixel 函数,尽管人们说它很慢。