Example #1
0
        //------------------------------------------------------------------- 
        //
        // Public Methods
        //
        //--------------------------------------------------------------------- 

        #region Public Methods 
 
        public static FixedSOMImage Create(FixedPage page, Image image, FixedNode fixedNode)
        { 
            Uri imageUri = null;
            if (image.Source is BitmapImage)
            {
                BitmapImage imageSource = image.Source as BitmapImage; 
                imageUri = imageSource.UriSource;
            } 
            else if (image.Source is BitmapFrame) 
            {
                BitmapFrame imageSource = image.Source as BitmapFrame; 
                imageUri = new Uri(imageSource.ToString(), UriKind.RelativeOrAbsolute);
            }
            Rect sourceRect = new Rect(image.RenderSize);
 
            GeneralTransform transform = image.TransformToAncestor(page);
            return new FixedSOMImage(sourceRect, transform, imageUri, fixedNode, image); 
        } 
Example #2
0
        public void ScaleImage(System.Windows.Point scalePoint, double scaleRatio)
        {
            if (!EnableImageScale)
            {
                return;
            }

            if (ImageWindow.Stretch == Stretch.Uniform)
            {
                return;
            }

            if (ImageWindowWidth == 0)
            {
                if (ScaleTransform.ScaleX == 1 && ScaleTransform.ScaleY == 1)
                {
                    ImageWindowWidth  = ImageWindow.ActualWidth;
                    ImageWindowHeight = ImageWindow.ActualHeight;
                }
            }

            if (ScaleTransform.ScaleX < MinScale && ScaleTransform.ScaleY < MinScale && scaleRatio < 1)
            {
                return;
            }

            if (ScaleTransform.ScaleX > MaxScale && ScaleTransform.ScaleY > MaxScale && scaleRatio > 1)
            {
                return;
            }

            ScaleTransform.CenterX = scalePoint.X;
            ScaleTransform.CenterY = scalePoint.Y;

            ScaleTransform.ScaleX *= scaleRatio;
            ScaleTransform.ScaleY *= scaleRatio;

            if (scaleRatio < 1)
            {
                Window window = Window.GetWindow(ImageWindow);
                System.Windows.Point point = ImageWindow.TransformToAncestor(window).Transform(new System.Windows.Point(0, 0));

                if (point.X - ImageWindowTopLeftPoint.X > 0)
                {
                    TranslateTransform.X -= point.X - ImageWindowTopLeftPoint.X;
                }

                if (point.X - ImageWindowTopLeftPoint.X + ImageWindowWidth * ScaleTransform.ScaleX < ImageWindowWidth)
                {
                    TranslateTransform.X += ImageWindowWidth * (1 - ScaleTransform.ScaleX) - (point.X - ImageWindowTopLeftPoint.X);
                }

                if (point.Y - ImageWindowTopLeftPoint.Y > 0)
                {
                    TranslateTransform.Y -= point.Y - ImageWindowTopLeftPoint.Y;
                }

                if (point.Y - ImageWindowTopLeftPoint.Y + ImageWindowHeight * ScaleTransform.ScaleY < ImageWindowHeight)
                {
                    TranslateTransform.Y = ImageWindowHeight * (1 - ScaleTransform.ScaleY) - (point.Y - ImageWindowTopLeftPoint.Y);
                }
            }
        }