Пример #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;
            }
        }
Пример #2
0
        protected override Artboard CreateArtboard()
        {
            this.platformSurface = this.viewModel.ProjectContext.Platform.CreateSurface();
            this.platformSurface.UnhandledException += new UnhandledExceptionEventHandler(this.SilverlightImageHost_UnhandledException);
            this.imageHost = this.platformSurface.CreateImageHost();
            this.imageHost.DocumentSizeChanged      += new EventHandler(this.ImageHost_DocumentSizeChanged);
            this.Document.DocumentRoot.TypesChanged += new EventHandler(this.DocumentRoot_TypesChanged);
            SilverlightArtboard silverlightArtboard = new SilverlightArtboard(this.platformSurface, this.Platform.ViewObjectFactory, new ViewExceptionCallback(((SceneView)this).OnExceptionWithUnknownSource), this.imageHost);

            this.platformSurface.BaseUri = this.ViewModel.ProjectContext.MakeDesignTimeUri(new Uri("/", UriKind.Relative), (string)null).OriginalString;
            return((Artboard)silverlightArtboard);
        }