/// <summary> /// Dropイベント /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void drop(object sender, DragEventArgs e) { string[] images = e.Data.GetData(DataFormats.FileDrop) as string[]; if (images == null) return; // キャプチャ中なら停止する if (captureImageWindow != null) { captureImageWindow.Close(); captureImageWindow = null; } if (isExecuting) { isExecuting = false; } // ヒストグラムを計算 Bitmap image = new Bitmap(images[0]); UInt32[] histogram = calcHistogram(image); // ヒストグラム表示 chart.ChartAreas.Clear(); chart.ChartAreas.Add("ChartArea1"); Series series = new Series(); series.ChartType = SeriesChartType.Column; series.MarkerStyle = MarkerStyle.None; for (int i = 0; i < histogram.Length; i++) { series.Points.AddXY((double)i, (double)histogram[i]); } chart.Series.Clear(); chart.Series.Add(series); // X軸の設定 chart.ChartAreas["ChartArea1"].AxisX.Minimum = 0; chart.ChartAreas["ChartArea1"].AxisX.Maximum = 255; chart.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false; // Y軸の設定 if (ScaleY != 0) { chart.ChartAreas["ChartArea1"].AxisY.Minimum = 0; chart.ChartAreas["ChartArea1"].AxisY.Maximum = ScaleY; } chart.ChartAreas["ChartArea1"].AxisY.MajorGrid.Enabled = false; chart.ChartAreas["ChartArea1"].AxisY.Enabled = AxisEnabled.False; // 画像を表示 CaptureImage = getBitmapImage(image); image.Dispose(); // 子Windows表示 captureImageWindow = new CaptureImageWindow(this); captureImageWindow.Show(); }
/// <summary> /// スタートボタン押下 /// </summary> /// <param name="parameter"></param> private void startExecute(object parameter) { isExecuting = true; Task.Run(() => { Bitmap screen; Graphics g; UInt32[] histo; while (isExecuting) { // スクリーンキャプチャ(70ms) selectedWindowRect = wm.GetWindowRectangle(SelectedProcess); if (selectedWindowRect == Rectangle.Empty) { isExecuting = false; App.Current.Dispatcher.Invoke(() => { captureImageWindow.Close(); captureImageWindow = null; RaiseCanExecuteChanged(); }); break; } UpdatePosition(); Rectangle captureRect = new Rectangle(selectedWindowRect.X + OffsetX, selectedWindowRect.Y + OffsetY, Width, Width / 2); screen = new Bitmap(captureRect.Width, captureRect.Height, PixelFormat.Format32bppArgb); g = Graphics.FromImage(screen); g.CopyFromScreen(captureRect.X, captureRect.Y, 0, 0, screen.Size); g.Dispose(); // 輝度計算(25ms) histo = calcHistogram(screen); // チャート表示(0ms) App.Current.Dispatcher.Invoke(() => { chart.ChartAreas.Clear(); chart.ChartAreas.Add("ChartArea1"); Series series = new Series(); series.ChartType = SeriesChartType.Column; series.MarkerStyle = MarkerStyle.None; for (int i = 0; i < histo.Length; i++) { series.Points.AddXY((double)i, (double)histo[i]); } chart.Series.Clear(); chart.Series.Add(series); // X軸の設定 chart.ChartAreas["ChartArea1"].AxisX.Minimum = 0; chart.ChartAreas["ChartArea1"].AxisX.Maximum = 255; chart.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false; // Y軸の設定 if (ScaleY != 0) { chart.ChartAreas["ChartArea1"].AxisY.Minimum = 0; chart.ChartAreas["ChartArea1"].AxisY.Maximum = ScaleY; } chart.ChartAreas["ChartArea1"].AxisY.MajorGrid.Enabled = false; chart.ChartAreas["ChartArea1"].AxisY.Enabled = AxisEnabled.False; }); // キャプチャ画像表示 CaptureImage = getBitmapImage(screen); screen.Dispose(); Thread.Sleep(100); } // 停止したらヒストグラムを消す App.Current.Dispatcher.Invoke(() => { chart.ChartAreas.Clear(); chart.Series.Clear(); }); }); captureImageWindow = new CaptureImageWindow(this); captureImageWindow.Show(); }