Ejemplo n.º 1
0
 private void CaptureZone_MouseLeave(object sender, MouseEventArgs e)
 {
     if (_isDrag && IsVisible)
     {
         WindowState = WindowState.Minimized;
         int left   = (int)(Canvas.GetLeft(_dragBorder) * _factor.X);
         int top    = (int)(Canvas.GetTop(_dragBorder) * _factor.Y);
         int width  = (int)(_dragBorder.Width * _factor.X);
         int height = (int)(_dragBorder.Height * _factor.Y);
         var rect   = new Rect
         {
             Left   = left,
             Right  = width + left,
             Bottom = top + height,
             Top    = top
         };
         var image = DisplayHelper.Capture(_monitorInfo, rect);
         NotifyHelper.InvokeNotify(NotifyEventType.ScreenCaptureDataBInd, new CaptureEventArgs()
         {
             CaptureViewMode = _captureViewMode,
             MonitorInfo     = _monitorInfo,
             CaptureImage    = image,
             Position        = rect
         });
         e.Handled   = true;
         WindowState = WindowState.Maximized;
     }
     _isDrag = false;
 }
Ejemplo n.º 2
0
        private void NotifyHelper_SaveEventTriggerModel(SaveEventTriggerModelArgs obj)
        {
            if (tab_content.SelectedContent is BaseContentView baseView)
            {
                var viewObj = _viewMap[baseView.Tag.ToString()];

                var process = comboProcess.SelectedValue as Process;

                var rect = new Rect();

                obj.CurrentEventTriggerModel.ProcessInfo = new ProcessInfo()
                {
                    ProcessName = process?.ProcessName,
                    Position    = rect
                };

                if (viewObj.View.Validate(obj.CurrentEventTriggerModel, out Message error))
                {
                    NativeHelper.GetWindowRect(process.MainWindowHandle, ref rect);

                    var path = viewObj.SaveFilePath;

                    _taskQueue.Enqueue(() =>
                    {
                        Dispatcher.Invoke(() =>
                        {
                            if (obj.CurrentEventTriggerModel is GameEventTriggerModel)
                            {
                                var model = obj.CurrentEventTriggerModel as GameEventTriggerModel;
                                ObjectExtensions.GetInstance <CacheDataManager>().MakeIndexTriggerModel(model);
                            }
                            else if (obj.CurrentEventTriggerModel is EventTriggerModel)
                            {
                                var model = obj.CurrentEventTriggerModel as EventTriggerModel;
                                ObjectExtensions.GetInstance <CacheDataManager>().MakeIndexTriggerModel(model);
                                SettingProcessMonitorInfo(model, process);
                            }
                        });
                        return(viewObj.View.Save(path));
                    }).ContinueWith(task =>
                    {
                        if (task.IsFaulted == false)
                        {
                            Dispatcher.Invoke(() =>
                            {
                                Clear();
                            });
                        }
                        else
                        {
                            this.MessageShow("Error", DocumentHelper.Get(Message.FailedSaveFile));
                        }
                    });
                }
                else
                {
                    this.MessageShow("Error", DocumentHelper.Get(error));
                }
            }
        }
Ejemplo n.º 3
0
        private Rect CalculatorRoiPosition(Rect processPosition, Rect capturePosition, MonitorInfo monitorInfo)
        {
            if (capturePosition.Width > processPosition.Width && capturePosition.Height > processPosition.Height)
            {
                (Application.Current.MainWindow as MetroWindow).MessageShow("Error", DocumentHelper.Get(Message.FailedInvalidateRoiCapturePosition));
                return(_dummyRect);
            }
            var correctCapturePosition = monitorInfo.Rect + capturePosition;
            var distance = processPosition - correctCapturePosition;

            return(capturePosition - distance);
        }
Ejemplo n.º 4
0
        private int CheckPercentageImage(RoiPositionModel roiPositionModel, Process process, Tuple <double, double, double> lower, Tuple <double, double, double> upper)
        {
            var applciationData = ObjectExtensions.GetInstance <ApplicationDataManager>().Find(process.ProcessName) ?? new ApplicationDataModel();

            if (DisplayHelper.ProcessCapture(process, out Bitmap bitmap, applciationData.IsDynamic))
            {
                var processPosition = new Rect();
                NativeHelper.GetWindowRect(process.MainWindowHandle, ref processPosition);

                var factor  = NativeHelper.GetSystemDPI();
                var factorX = 1.0F * factor.X / ConstHelper.DefaultDPI;
                var factorY = 1.0F * factor.Y / ConstHelper.DefaultDPI;

                var realLeft = roiPositionModel.RoiPosition.Left - ((processPosition.Left - roiPositionModel.MonitorInfo.Rect.Left));
                var realTop  = roiPositionModel.RoiPosition.Top - (processPosition.Top - roiPositionModel.MonitorInfo.Rect.Top);

                var realWidth  = (int)Math.Truncate(roiPositionModel.RoiPosition.Width * factorX);
                var realHeight = (int)Math.Truncate(roiPositionModel.RoiPosition.Height * factorY);

                //var realWidth = realLeft + roiPositionModel.RoiPosition.Width;
                //var realHeight = realTop + roiPositionModel.RoiPosition.Height;


                var roi = new Rect()
                {
                    Left   = 327,
                    Right  = 1563,
                    Top    = 548,
                    Bottom = 773,
                };

                var roiBitmap = OpenCVHelper.MakeRoiImage(bitmap, roi);

                roiBitmap.Save("crop.jpg");

                canvasCaptureImage.Background = new ImageBrush(roiBitmap.ToBitmapSource());

                var percent = OpenCVHelper.SearchImagePercentage(roiBitmap, lower, upper);
            }
            return(0);
        }
Ejemplo n.º 5
0
        private bool Validate(EventTriggerModel model)
        {
            var process = comboProcess.SelectedValue as Process;

            model.ProcessInfo = new ProcessInfo()
            {
                ProcessName = process?.ProcessName,
                Position    = new Rect()
            };

            if (TryModelValidate(model, out Message error))
            {
                var rect = new Rect();

                NativeHelper.GetWindowRect(process.MainWindowHandle, ref rect);
                model.ProcessInfo.Position = rect;
                if (model.EventType != EventType.Mouse)
                {
                    foreach (var monitor in DisplayHelper.MonitorInfo())
                    {
                        if (monitor.Rect.IsContain(rect))
                        {
                            if (model.MonitorInfo != null)
                            {
                                model.Image = model.Image.Resize((int)(model.Image.Width * (monitor.Dpi.X * 1.0F / model.MonitorInfo.Dpi.X)), (int)(model.Image.Height * (monitor.Dpi.Y * 1.0F / model.MonitorInfo.Dpi.Y)));
                            }

                            model.MonitorInfo = monitor;
                            break;
                        }
                    }
                }
                return(true);
            }
            else
            {
                this.MessageShow("Error", DocumentHelper.Get(error));
                return(false);
            }
        }
Ejemplo n.º 6
0
        private void SettingProcessMonitorInfo(IBaseEventTriggerModel model, Process process)
        {
            var rect = new Rect();

            NativeHelper.GetWindowRect(process.MainWindowHandle, ref rect);
            model.ProcessInfo.Position = rect;

            if (model.EventType != EventType.Mouse)
            {
                foreach (var monitor in DisplayHelper.MonitorInfo())
                {
                    if (monitor.Rect.IsContain(rect))
                    {
                        if (model.MonitorInfo != null)
                        {
                            model.Image = model.Image.Resize((int)(model.Image.Width * (monitor.Dpi.X * 1.0F / model.MonitorInfo.Dpi.X)), (int)(model.Image.Height * (monitor.Dpi.Y * 1.0F / model.MonitorInfo.Dpi.Y)));
                        }

                        model.MonitorInfo = monitor;
                        break;
                    }
                }
            }
        }