C# 使用getpixel/lockbits,每个显示器的颜色值不同

C# 使用getpixel/lockbits,每个显示器的颜色值不同,c#,pixel,getpixel,lockbits,C#,Pixel,Getpixel,Lockbits,我正在尝试创建一个返回特定像素颜色值的方法。我遇到的问题是,同一段代码在不同的监视器上返回不同的ARGB 当前我正在使用此方法: public static Color GetColorFromPosition(string process, int x, int y) { //using bitmap object to do actions using (Bitmap Capture = CaptureApplication(Path.GetF

我正在尝试创建一个返回特定像素颜色值的方法。我遇到的问题是,同一段代码在不同的监视器上返回不同的ARGB

当前我正在使用此方法:

    public static Color GetColorFromPosition(string process, int x, int y)
    {
        //using bitmap object to do actions
        using (Bitmap Capture = CaptureApplication(Path.GetFileNameWithoutExtension(process)))
        {
            //copy specific part of screen and push it into bmp
            Color result = Capture.Clone(new Rectangle(x, y, 1, 1), Capture.PixelFormat).GetPixel(0,0);

            return result;
        }
    }
captureapplication方法如下所示(方法获取打开的应用程序的快照):

这将捕获一个打开的应用程序窗口,然后使用getpixel获取给定像素的ARGB值。举个例子,我想要x=100和y=100的颜色。在第一台计算机上,它将返回[A=255,R=6,G=158,B=12],在另一台计算机上,我得到[A=255,R=6,G=157,B=13]。结果略有不同


我的问题是为什么会发生这种情况,是否有解决办法?我也尝试过使用lockbits代替getpixel,但同样的问题仍然存在

两台计算机都设置为32位颜色质量吗?显示器的驱动程序不同。位图的宽度和高度将随监视器的大小而变化。您可以有一个5英寸x 7英寸的位图和一个24英寸x 36英寸的显示器。因此,驱动程序将位图缩放到屏幕上,并对颜色进行平均。@jaydepjadav它们都是“1920 x 1080,真彩色(32位),60赫兹”这些像素是什么?图像?放大?压缩的?文本?Cleartype?-有多种渲染器将使用随机抖动。。
    public static Bitmap CaptureApplication(string procName)
    {
        Rectangle clientArea = GetProcessWindowRect(procName);

        Bitmap bp = new Bitmap(clientArea.Width, clientArea.Height, PixelFormat.Format32bppArgb);
        Graphics g = Graphics.FromImage(bp);
        g.CopyFromScreen(clientArea.Left, clientArea.Top, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);

        return bp;
    }