示例#1
0
        // Receive an event containing new image processing parameters.
        // Store these parameters and then try to update the image
        public async void AdjustImage_EventHandler(object sender, ImageAdjusterEventArgs e)
        {
            if (e == null)
            {
                // Shouldn't happen, but...
                return;
            }

            string path = DataEntryHandler.TryGetFilePathFromGlobalDataHandler();

            if (String.IsNullOrEmpty(path))
            {
                // The file cannot be opened or is not displayable.
                // Signal change in image state, which essentially says there is no displayable image to adjust (consumed by ImageAdjuster)
                this.OnImageStateChanged(new ImageStateEventArgs(false)); //  Signal change in image state (consumed by ImageAdjuster)
                return;
            }

            if (e.OpenExternalViewer)
            {
                // The event says to open an external photo viewer. Try to do so.
                // Note that we don't do any image processing on this event if if this is the case.
                if (ProcessExecution.TryProcessStart(path) == false)
                {
                    // Can't open the image file with an external view. Note that file must exist at this point as we checked for that above.
                    Dialogs.MarkableCanvasCantOpenExternalPhotoViewerDialog(Util.GlobalReferences.MainWindow, Path.GetExtension(path));
                }
                return;
            }

            // Process the image based on the current image processing arguments.
            if (e.ForceUpdate == false && (e.Contrast == this.lastContrast && e.Brightness == this.lastBrightness && e.DetectEdges == this.lastDetectEdges && e.Sharpen == this.lastSharpen && e.UseGamma == this.lastUseGamma && e.GammaValue == this.lastGammaValue))
            {
                // If there is no change from the last time we processed an image, abort as it would not make any difference to what the user sees
                return;
            }
            this.contrast    = e.Contrast;
            this.brightness  = e.Brightness;
            this.detectEdges = e.DetectEdges;
            this.sharpen     = e.Sharpen;
            this.useGamma    = e.UseGamma;
            this.gammaValue  = e.GammaValue;
            this.timerImageProcessingUpdate.Start();
            await UpdateAndProcessImage().ConfigureAwait(true);
        }
 protected virtual void OnImageProcessingParametersChanged(ImageAdjusterEventArgs e)
 {
     this.ImageProcessingParametersChanged?.Invoke(this, e);
 }