예제 #1
0
        private void OnImageOpened(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            var image  = sender as Windows.UI.Xaml.Controls.Image;
            var canvas = image.Parent as Windows.UI.Xaml.Controls.Canvas;

            // Make the image 75% of the canvas and position it at the center of the canvas
            var scale = 0.75 * System.Math.Min(
                (canvas.ActualHeight / image.ActualHeight),
                (canvas.ActualWidth / image.ActualWidth));

            image.RenderTransform = new Windows.UI.Xaml.Media.TransformGroup
            {
                Children =
                {
                    new Windows.UI.Xaml.Media.TranslateTransform
                    {
                        X = (canvas.ActualWidth - image.ActualWidth) / 2,
                        Y = (canvas.ActualHeight - image.ActualHeight) / 2
                    },
                    new Windows.UI.Xaml.Media.ScaleTransform
                    {
                        CenterX = canvas.ActualWidth / 2,
                        CenterY = canvas.ActualHeight / 2,
                        ScaleX  = scale,
                        ScaleY  = scale
                    },
                }
            };

            this._manipulationManager = new Manipulations.ManipulationManager(image, canvas);
            this._manipulationManager.OnFilterManipulation = Manipulations.ManipulationFilter.Clamp;
            this._manipulationManager.Configure(true, false, true, true);
        }
예제 #2
0
        private void OnImageOpened(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            var image  = sender as Windows.UI.Xaml.Controls.Image;
            var canvas = image.Parent as Windows.UI.Xaml.Controls.Canvas;

            // Make the image 70% of the canvas and position it at the center of the canvas
            var scale = 0.7 * System.Math.Min(
                (canvas.ActualHeight / image.ActualHeight),
                (canvas.ActualWidth / image.ActualWidth));

            image.RenderTransform = new Windows.UI.Xaml.Media.TransformGroup
            {
                Children =
                {
                    new Windows.UI.Xaml.Media.TranslateTransform
                    {
                        X = (canvas.ActualWidth - image.ActualWidth) / 2,
                        Y = (canvas.ActualHeight - image.ActualHeight) / 2
                    },
                    new Windows.UI.Xaml.Media.ScaleTransform
                    {
                        CenterX = canvas.ActualWidth / 2,
                        CenterY = canvas.ActualHeight / 2,
                        ScaleX  = scale,
                        ScaleY  = scale
                    },
                }
            };

            // Create and configure manipulation manager for this image
            // leftImage can only be rotated, while rightImage can also be translated
            var manManager = new Manipulations.ManipulationManager(image, canvas);

            if (image == leftImage)
            {
                manManager.OnFilterManipulation = Manipulations.ManipulationFilter.RotateAboutCenter;
                manManager.Configure(false, true, false, true);
            }
            else if (image == rightImage)
            {
                manManager.OnFilterManipulation = Manipulations.ManipulationFilter.ClampCenterOfMass;
                manManager.Configure(false, true, true, true);
            }
            else
            {
                // Should never happen
                throw new System.Exception("RotatePage.OnImageOpened");
            }
            this._manipulationManager[image] = manManager;
        }