コード例 #1
0
ファイル: SvgImageRenderer.cs プロジェクト: p69/SvgForXaml
        private static void RendererImage(Stream stream, SvgImageRendererSettings settings)
        {
            var svg      = settings.Document;
            var viewPort = svg.RootElement.ViewPort;

            if (!viewPort.HasValue)
            {
                throw new ArgumentException(nameof(settings));
            }

            var width  = viewPort.Value.Width;
            var height = viewPort.Value.Height;
            var device = CanvasDevice.GetSharedDevice();

            using (var offScreen = new CanvasRenderTarget(device, width, height, settings.Scaling * 96.0F))
            {
                using (var renderer = new Win2dRenderer(offScreen, svg))
                    using (var session = offScreen.CreateDrawingSession())
                    {
                        session.Clear(Colors.Transparent);
                        renderer.Render(width, height, session);
                    }
                offScreen.SaveAsync(stream.AsRandomAccessStream(), (CanvasBitmapFileFormat)settings.Format, settings.Quality).AsTask().GetAwaiter().GetResult();
            }
        }
コード例 #2
0
		public static Task RendererImageAsync(StorageFile file, SvgImageRendererSettings settings, CancellationToken token)
		{
			return ThreadPool.RunAsync(_ =>
			{
				using (var stream = file.OpenStreamForWriteAsync().GetAwaiter().GetResult())
				{
					RendererImage(stream, settings);
				}
			}).AsTask(token);
		}
コード例 #3
0
ファイル: SvgImageRenderer.cs プロジェクト: p69/SvgForXaml
 public static Task RendererImageAsync(StorageFile file, SvgImageRendererSettings settings, CancellationToken token)
 {
     return(ThreadPool.RunAsync(_ =>
     {
         using (var stream = file.OpenStreamForWriteAsync().GetAwaiter().GetResult())
         {
             RendererImage(stream, settings);
         }
     }).AsTask(token));
 }
コード例 #4
0
		private static void RendererImage(Stream stream, SvgImageRendererSettings settings)
		{
			var svg = settings.Document;
			var viewPort = svg.RootElement.ViewPort;
			if (!viewPort.HasValue) throw new ArgumentException(nameof(settings));

			var width = viewPort.Value.Width;
			var height = viewPort.Value.Height;
			var device = CanvasDevice.GetSharedDevice();
			using (var offScreen = new CanvasRenderTarget(device, width, height, settings.Scaling * 96.0F))
			{
				using (var renderer = new Win2dRenderer(offScreen, svg))
				using (var session = offScreen.CreateDrawingSession())
				{
					session.Clear(Colors.Transparent);
					renderer.Render(width, height, session);
				}
				offScreen.SaveAsync(stream.AsRandomAccessStream(), (CanvasBitmapFileFormat)settings.Format, settings.Quality).AsTask().GetAwaiter().GetResult();
			}
		}
コード例 #5
0
		public static Task RendererImageAsync(Stream stream, SvgImageRendererSettings settings, CancellationToken token)
		{
			return ThreadPool.RunAsync(_ => RendererImage(stream, settings)).AsTask(token);
		}
コード例 #6
0
		public static Task RendererImageAsync(Stream stream, SvgImageRendererSettings settings)
		{
			return ThreadPool.RunAsync(_ => RendererImage(stream, settings)).AsTask();
		}
コード例 #7
0
		public static Task RendererImageAsync(StorageFile file, SvgImageRendererSettings settings)
			=> RendererImageAsync(file, settings, CancellationToken.None);
コード例 #8
0
ファイル: SvgImageRenderer.cs プロジェクト: p69/SvgForXaml
 public static Task RendererImageAsync(Stream stream, SvgImageRendererSettings settings, CancellationToken token)
 {
     return(ThreadPool.RunAsync(_ => RendererImage(stream, settings)).AsTask(token));
 }
コード例 #9
0
ファイル: SvgImageRenderer.cs プロジェクト: p69/SvgForXaml
 public static Task RendererImageAsync(Stream stream, SvgImageRendererSettings settings)
 {
     return(ThreadPool.RunAsync(_ => RendererImage(stream, settings)).AsTask());
 }
コード例 #10
0
ファイル: SvgImageRenderer.cs プロジェクト: p69/SvgForXaml
 public static Task RendererImageAsync(StorageFile file, SvgImageRendererSettings settings)
 => RendererImageAsync(file, settings, CancellationToken.None);