public static Image ImageCrop(int nPID, eImagetype type) { int nType = (int)type; Image img = null; try { Process process = new Process(); ProcessControl.FindProcess(ref process, nPID); ScreenCapture sc = new ScreenCapture(); if (type != eImagetype.total) { img = sc.CaptureWindow(process.MainWindowHandle, List_Rect[nType]); } else { img = sc.CaptureWindow(process.MainWindowHandle); } } catch (Exception e) { MessageBox.Show(e.ToString()); img = null; } finally { img.Save(m_strFilePath + "temp.bmp", System.Drawing.Imaging.ImageFormat.Bmp); } return(img); }
private bool ImageCompareSeq(string strPath, eImagetype imagetype, int nID, int nTry = 10, int nSleepTime = 100) { bool bRet = false; try { int n = 0; do { bRet = ImageProc.ImageCompare(strPath, new Bitmap(ImageProc.ImageCrop(nID, imagetype))); if (bRet == true) { break; } Thread.Sleep(nSleepTime);//Task.Delay(1000); } while (n++ < nTry); } catch (Exception e) { logs.Format(e.ToString()); bRet = false; } return(bRet); }