Esempio n. 1
0
        private void ApplyCinemagraphButton_Click(object sender, RoutedEventArgs e)
        {
            if (CinemagraphInkCanvas.Strokes.Count == 0)
            {
                ShowWarning(ResMessage("Editor.Cinemagraph.WarningNoDrawing"), MessageIcon.Info);
                return;
            }

            ActionStack.Did(ListFrames);

            var dpi = ListFrames[0].ImageLocation.DpiOf();
            var scaledSize = ListFrames[0].ImageLocation.ScaledSize();

            #region Get the Strokes and Clip the Image

            var image = ListFrames[0].ImageLocation.SourceFrom();
            var rectangle = new RectangleGeometry(new Rect(new System.Windows.Point(0, 0), new System.Windows.Size(image.PixelWidth, image.PixelHeight)));
            Geometry geometry = Geometry.Empty;

            foreach (Stroke stroke in CinemagraphInkCanvas.Strokes)
            {
                geometry = Geometry.Combine(geometry, stroke.GetGeometry(), GeometryCombineMode.Union, null);
            }

            geometry = Geometry.Combine(geometry, rectangle, GeometryCombineMode.Xor, null);

            var clippedImage = new System.Windows.Controls.Image
            {
                Height = image.PixelHeight,
                Width = image.PixelWidth,
                Source = image,
                Clip = geometry
            };
            clippedImage.Measure(scaledSize);
            clippedImage.Arrange(new Rect(scaledSize));

            var imageRender = clippedImage.GetRender(dpi, scaledSize);

            #endregion

            Cursor = Cursors.AppStarting;

            _overlayFramesDel = Overlay;
            _overlayFramesDel.BeginInvoke(imageRender, dpi, true, OverlayCallback, null);

            ClosePanel();
        }