Ejemplo n.º 1
0
        public VisualCapturer(SilverlightSceneView sceneView, Size targetSize)
            : base(targetSize)
        {
            SilverlightArtboard silverlightArtboard = (SilverlightArtboard)sceneView.Artboard;
            Rect      documentBounds       = silverlightArtboard.DocumentBounds;
            ImageHost silverlightImageHost = silverlightArtboard.SilverlightImageHost;

            if (documentBounds.Width <= 0.0 || documentBounds.Height <= 0.0)
            {
                return;
            }
            using (new VisualCapturer.ImageHostActivator(silverlightImageHost))
            {
                silverlightImageHost.SetTransformMatrix(Matrix.Identity, new Vector(1.0, 1.0));
                silverlightImageHost.Measure(documentBounds.Size);
                silverlightImageHost.Arrange(documentBounds);
                silverlightImageHost.UpdateLayout();
                silverlightImageHost.Redraw(false);
                double proportionalScale = RectExtensions.GetProportionalScale(documentBounds, targetSize);
                documentBounds.Scale(proportionalScale, proportionalScale);
                Image image1 = new Image();
                image1.Source          = silverlightImageHost.InternalSource;
                image1.LayoutTransform = (Transform) new ScaleTransform(proportionalScale, proportionalScale);
                Image image2 = image1;
                image2.Measure(documentBounds.Size);
                image2.Arrange(documentBounds);
                this.DefaultSize = new Size(documentBounds.Width, documentBounds.Height);
                this.visual      = (Visual)image2;
            }
        }
Ejemplo n.º 2
0
        private static Rect GetScaledRectangle(FrameworkElement element, Size targetSize, out double scale)
        {
            Rect rect = new Rect(0.0, 0.0, 0.0, 0.0);

            element.Measure(rect.Size);
            element.Arrange(rect);
            element.UpdateLayout();
            rect  = new Rect(0.0, 0.0, element.ActualWidth, element.ActualHeight);
            scale = RectExtensions.GetProportionalScale(rect, targetSize);
            rect.Scale(scale, scale);
            return(rect);
        }