Как сделать: "copyfromscreen" осведомлен о масштабировании рабочего стола windows?
Приведенный ниже код при вызове для получения пикселя на нескольких экранах или на одном экране с увеличением дисплея на нем, например 150%, он не получает правильный пиксель в 3840x2160 пикселей, он получает еще один пиксель из-за увеличения, как исправить это плз?
Что я уже пробовал:
static Color GetPixel(Point p) { using (var bitmap = new Bitmap(1, 1)) { using (var graphics = Graphics.FromImage(bitmap)) { graphics.CopyFromScreen(p, new Point(0, 0), new Size(1, 1)); } return bitmap.GetPixel(0, 0); } }
Я делаю это:
if (formMain.WindowState != FormWindowState.Minimized) { if ( (ClassGetPixelWithDisplayZoomInMind.get_pixel(formMain.PointToScreen(new Point(formMain.pictureBoxCleanup.Right + 50, formMain.pictureBoxCleanup.Top + 20))) == Color.Gray) && (ClassGetPixelWithDisplayZoomInMind.get_pixel(formMain.PointToScreen(new Point(formMain.pictureBoxCleanup.Right + 50 + 1, formMain.pictureBoxCleanup.Top + 20))) == Color.DarkGray) && (ClassGetPixelWithDisplayZoomInMind.get_pixel(formMain.PointToScreen(new Point(formMain.pictureBoxCleanup.Right + 50 + 2, formMain.pictureBoxCleanup.Top + 20))) == Color.Brown) && (ClassGetPixelWithDisplayZoomInMind.get_pixel(formMain.PointToScreen(new Point(formMain.pictureBoxCleanup.Right + 50, formMain.pictureBoxCleanup.Top + 21))) == Color.RosyBrown) && (ClassGetPixelWithDisplayZoomInMind.get_pixel(formMain.PointToScreen(new Point(formMain.pictureBoxCleanup.Right + 50 + 1, formMain.pictureBoxCleanup.Top + 21))) == Color.DarkSlateGray) && (ClassGetPixelWithDisplayZoomInMind.get_pixel(formMain.PointToScreen(new Point(formMain.pictureBoxCleanup.Right + 50 + 2, formMain.pictureBoxCleanup.Top + 21))) == Color.DarkGray) && (ClassGetPixelWithDisplayZoomInMind.get_pixel(formMain.PointToScreen(new Point(formMain.pictureBoxCleanup.Right + 50, formMain.pictureBoxCleanup.Top + 22))) == Color.SlateGray) && (ClassGetPixelWithDisplayZoomInMind.get_pixel(formMain.PointToScreen(new Point(formMain.pictureBoxCleanup.Right + 50 + 1, formMain.pictureBoxCleanup.Top + 22))) == Color.LightSlateGray) && (ClassGetPixelWithDisplayZoomInMind.get_pixel(formMain.PointToScreen(new Point(formMain.pictureBoxCleanup.Right + 50 + 2, formMain.pictureBoxCleanup.Top + 22))) == Color.LightGray)) { Program.DoMouseClick(formMain.PointToScreen(new Point(formMain.pictureBoxCleanup.Right + 50 + 1, formMain.pictureBoxCleanup.Top + 21))); } }
А это:
private void FormMain_Paint(object sender, PaintEventArgs e) { ClassSetGetPixel.SetPixel(this, pictureBoxCleanup.Right + 50, 20, Color.Gray); ClassSetGetPixel.SetPixel(this, pictureBoxCleanup.Right + 50 + 1,20, Color.DarkGray); ClassSetGetPixel.SetPixel(this, pictureBoxCleanup.Right + 50 + 2, 20, Color.Brown); ClassSetGetPixel.SetPixel(this, pictureBoxCleanup.Right + 50, 21, Color.RosyBrown); ClassSetGetPixel.SetPixel(this, pictureBoxCleanup.Right + 50 + 1, 21, Color.White); ClassSetGetPixel.SetPixel(this, pictureBoxCleanup.Right + 50 + 2, 21, Color.DarkGray); ClassSetGetPixel.SetPixel(this, pictureBoxCleanup.Right + 50, 22, Color.SlateGray); ClassSetGetPixel.SetPixel(this, pictureBoxCleanup.Right + 50 + 1, 22, Color.LightSlateGray); ClassSetGetPixel.SetPixel(this, pictureBoxCleanup.Right + 50 + 2, 22, Color.LightGray); }