Example #1
0
 internal static void ExportSvg(IToolContext context, string path, IContainerView containerView)
 {
     using var wstream = new SKFileWStream(path);
     using var canvas  = SKSvgCanvas.Create(SKRect.Create(0, 0, (int)containerView.Width, (int)containerView.Height), wstream);
     using var skiaContainerPresenter = new SkiaExportContainerPresenter(context, containerView);
     skiaContainerPresenter.Draw(canvas, containerView.Width, containerView.Height, 0, 0, 1.0, 1.0);
 }
Example #2
0
        static void Main(string[] args)
        {
            var examples = new IExampleRunner[]
            {
                new CannonTest(),
                new Clock(),
                new SingleSphereExample(),
                new MultipleSphereTest(),
                new ShadedSphere(),
                new CameraTest(),
                new DualLightCameraTest(),
                new PlaneExample(),
                new PatternExample(),
            };

            var outputDirectory = Path.Combine(new DirectoryInfo(Environment.CurrentDirectory).Parent.Parent.Parent.Parent.ToString(), "Examples");

            var examplesToRun = examples.Select((x, index) => new { Example = x, index })
                                .Skip(examples.Length - 1);

            foreach (var item in examplesToRun)
            {
                var filename  = Path.Combine(outputDirectory, $"{item.index:00}_{item.Example.GetType().Name}.png");
                var stopwatch = Stopwatch.StartNew();
                var canvas    = item.Example.Run();
                stopwatch.Stop();

                using var file   = new SKFileWStream(filename);
                using var bitmap = canvas.RenderToBitmap();
                SKPixmap.Encode(file, bitmap, SKEncodedImageFormat.Png, 100);

                Console.WriteLine($"Canvas rendered in {stopwatch.ElapsedMilliseconds:N}ms");
            }
        }
Example #3
0
 internal static void ExportXps(IToolContext context, string path, IContainerView containerView)
 {
     using var stream = new SKFileWStream(path);
     using var xps    = SKDocument.CreateXps(stream, SKDocument.DefaultRasterDpi);
     using var canvas = xps.BeginPage((float)containerView.Width, (float)containerView.Height);
     using var skiaContainerPresenter = new SkiaExportContainerPresenter(context, containerView);
     skiaContainerPresenter.Draw(canvas, containerView.Width, containerView.Height, 0, 0, 1.0, 1.0);
     xps.Close();
 }
Example #4
0
        /// <summary>
        /// Generate a splashscreen.
        /// </summary>
        /// <param name="posters">The poster paths.</param>
        /// <param name="backdrops">The landscape paths.</param>
        /// <param name="outputPath">The output path.</param>
        public void GenerateSplash(IReadOnlyList <string> posters, IReadOnlyList <string> backdrops, string outputPath)
        {
            using var wall        = GenerateCollage(posters, backdrops);
            using var transformed = Transform3D(wall);

            using var outputStream = new SKFileWStream(outputPath);
            using var pixmap       = new SKPixmap(new SKImageInfo(FinalWidth, FinalHeight), transformed.GetPixels());
            pixmap.Encode(outputStream, StripCollageBuilder.GetEncodedFormat(outputPath), 90);
        }
Example #5
0
        private void SaveButton_OnClicked(object sender, RoutedEventArgs e)
        {
            var width  = Canvas.CanvasSize.Width;
            var bounds = SKRect.Create(0, 0, width, width);

            using (var stream = new SKFileWStream(@"C:\Temp\grid.svg"))
                using (var writer = new SKXmlStreamWriter(stream))
                    using (var canvas = SKSvgCanvas.Create(bounds, writer))
                    {
                        _hexPainter.DrawGrid(_gol.Grid, canvas, _cellRadius);
                    }
        }