/// <summary> /// 截图测试 /// </summary> static void JieTuCeShi() { var bar = WinApi.FindWindow(null, "开具增值税普通发票"); var child = WinApi.FindWindowEx(bar, IntPtr.Zero, null, null); var child1 = WinApi.FindWindowEx(child, IntPtr.Zero, null, null); var child2 = WinApi.FindWindowEx(child, child1, null, null); //Console.WriteLine($"bar:{bar},child:{child},child1:{child1},child2:{child2}"); var map = WinApi.GetWindowCapture(child2); Color destColor1 = Color.FromArgb(156, 175, 51); // Color destColor2 = Color.FromArgb(240, 132, 60); // bool isNoTax = false; var X = 0; for (var i = map.Width - 350; i < map.Width - 310; i++)//310,350,10,40 { for (var j = 11; j < 39; j++) { var color = map.GetPixel(i, j); if (color.Equals(destColor1)) { Console.WriteLine($"no tax success,(x:{i},y:{j})"); isNoTax = true; X = i; break; } if (color.Equals(destColor2)) { Console.WriteLine($"tax success,(x:{i},y:{j})"); isNoTax = false; X = i; break; } } } if (!isNoTax) { WinApi.ClickLocation(child2, X + 20, 25);//点击价格,不含税 } Console.WriteLine("========================================================="); //WinApi.ClickLocation(child2, X + 20, 25); for (var i = 0; i < map.Width; i++) { var pixel = map.GetPixel(i, 25); var r3 = (pixel.R - destColor1.R) / 256.0; var g3 = (pixel.G - destColor1.G) / 256.0; var b3 = (pixel.B - destColor1.B) / 256.0; var diff = Math.Sqrt(r3 * r3 + g3 * g3 + b3 * b3); if (diff <= 0.05) { Console.WriteLine($"success,(x:{i},y:25)"); } } //map.GetPixel(); //map.Save($"{DateTime.Now.Ticks}.png"); }
/// <summary> /// 截图 /// </summary> /// <param name="hwnd"></param> static void CapturePic(IntPtr hwnd) { var map = WinApi.GetWindowCapture(hwnd); map.Save($"{DateTime.Now:yyyyMMddhhmmss}.png"); }