private bool ShowImageCaptureDialog(out string filepath, out Rectangle rect) { filepath = null; var screen = ImageCapture.BitmapFromScreen(); // スクリーン範囲ドラッグ var cs = new ScreenSelection(); rect = cs.ShowGetRectDialog(screen, "画像領域をドラッグしてください"); if (rect.IsEmpty) { return(false); } // 指定範囲をファイルに保存 filepath = ShowSaveFileDialog(); if (filepath == null) { return(false); } Bitmap bmp = screen.Clone(rect, screen.PixelFormat); bmp.Save(filepath, ImageFormat.Bmp); return(true); }
private void ShowGetDragDialog(out System.Drawing.Point[] line) { // スクリーン範囲ドラッグ var cs = new ScreenSelection(); line = cs.ShowGetLineDialog(ImageCapture.BitmapFromScreen(), "ドラッグしてください"); }
static public System.Drawing.Point SerchImage(string img_path, int retry_num = 10, int retry_sleep = 1000, double err_threshold = 0.05) { for (int i = 0; i < retry_num; i++) { Bitmap screen = ImageCapture.BitmapFromScreen(); Bitmap bmp = (Bitmap)Bitmap.FromFile(img_path); var pos = ImageSearch.Search(screen, bmp, err_threshold); if (!pos.IsEmpty) { return(pos); } Console.WriteLine($"{Path.GetFileName(img_path)} not found."); Thread.Sleep(retry_sleep); } MessageBox.Show($"画像が見つかりません {img_path}\n"); return(System.Drawing.Point.Empty); }
/// <summary> /// 画像キャプチャとそこからのクリックオフセット位置を取得するダイアログ /// </summary> /// <param name="filepath"></param> /// <param name="offset"></param> private void ShowGetClickOffsetFromCapture(out string filepath, out System.Drawing.Point offset) { filepath = null; offset = System.Drawing.Point.Empty; var screen = ImageCapture.BitmapFromScreen(); // スクリーン範囲ドラッグ var cs = new ScreenSelection(); var captureRect = cs.ShowGetRectDialog(screen, "画像領域をドラッグしてください"); if (captureRect.IsEmpty) { return; } // 指定範囲をファイルに保存 filepath = ShowSaveFileDialog(); if (filepath == null) { return; } Bitmap bmp = screen.Clone(captureRect, screen.PixelFormat); bmp.Save(filepath, ImageFormat.Bmp); // 相対クリック一取得 cs = new ScreenSelection(); var clickPoint = cs.ShowGetPointDialog(screen, "クリックする座標を指定してください"); if (clickPoint.IsEmpty) { return; } // 画像の切り出し offset = new System.Drawing.Point(); offset.X = clickPoint.X - captureRect.X; offset.Y = clickPoint.Y - captureRect.Y; }
/// <summary> /// 画像キャプチャとそこからのドラッグ位置を取得する /// </summary> /// <param name="filepath"></param> /// <param name="offset"></param> private void ShowGetDragOffsetFromCapture(out string filepath, out System.Drawing.Point[] line) { filepath = null; line = null; var screen = ImageCapture.BitmapFromScreen(); // スクリーン範囲ドラッグ var cs = new ScreenSelection(); var captureRect = cs.ShowGetRectDialog(screen, "画像領域をドラッグしてください"); if (captureRect.IsEmpty) { return; } // 指定範囲をファイルに保存 filepath = ShowSaveFileDialog(); if (filepath == null) { return; } Bitmap bmp = screen.Clone(captureRect, screen.PixelFormat); bmp.Save(filepath, ImageFormat.Bmp); // 相対クリック一取得 cs = new ScreenSelection(); var absLine = cs.ShowGetLineDialog(screen, "ドラッグしてください"); // 画像の切り出し line = new System.Drawing.Point[2]; line[0].X = absLine[0].X - captureRect.X; line[0].Y = absLine[0].Y - captureRect.Y; line[1].X = absLine[1].X - captureRect.X; line[1].Y = absLine[1].Y - captureRect.Y; }
private void ShowGetClickPosDialog(out System.Drawing.Point pos) { var cs = new ScreenSelection(); pos = cs.ShowGetPointDialog(ImageCapture.BitmapFromScreen(), "クリックする座標を指定してください"); }