C# 获取透明控件后面的像素



我正在构建一个能够获取屏幕部分像素像素的应用程序。我正在尝试通过使表单的背景透明来做到这一点,以便您可以透过表单看到。问题是,当我使用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 函数,尽管人们说它很慢。

我想你正在寻找

Graphics.CopyFromSreen(..);

创建一个Image,使用Graphics.CopyFromSreen从屏幕上复制像素。然后,您可以使用bitmap.GetPixel()来获取颜色pixel

请参阅 Graphics.CopyFromSreen 了解更多信息

最新更新