• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# CanvasRenderTarget类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中CanvasRenderTarget的典型用法代码示例。如果您正苦于以下问题:C# CanvasRenderTarget类的具体用法?C# CanvasRenderTarget怎么用?C# CanvasRenderTarget使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CanvasRenderTarget类属于命名空间,在下文中一共展示了CanvasRenderTarget类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Button_Click

        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            using (var stream = await Root.RenderToRandomAccessStream())
            {
                var device = new CanvasDevice();
                var bitmap = await CanvasBitmap.LoadAsync(device, stream);

                var renderer = new CanvasRenderTarget(device, bitmap.SizeInPixels.Width, bitmap.SizeInPixels.Height, bitmap.Dpi);

                using (var ds = renderer.CreateDrawingSession())
                {
                    var blur = new GaussianBlurEffect();
                    blur.BlurAmount = 5.0f;
                    blur.Source = bitmap;
                    ds.DrawImage(blur);
                }

                stream.Seek(0);
                await renderer.SaveAsync(stream, CanvasBitmapFileFormat.Png);

                BitmapImage image = new BitmapImage();
                image.SetSource(stream);
                Blured.Source = image;
            }
        }
开发者ID:KooKiz,项目名称:comet,代码行数:25,代码来源:UIElementToImageTest.xaml.cs


示例2: MultithreadedSaveToFile

        public void MultithreadedSaveToFile()
        {
            //
            // This test can create a deadlock if the SaveAsync code holds on to the
            // ID2D1Multithread resource lock longer than necessary.
            //
            // A previous implementation waited until destruction of the IAsyncAction before calling Leave().  
            // In managed code this can happen on an arbitrary thread and so could result in deadlock situations
            // where other worker threads were waiting for a Leave on the original thread that never arrived.
            //

            using (new DisableDebugLayer()) // 6184116 causes the debug layer to fail when CanvasBitmap::SaveAsync is called
            {
                var task = Task.Run(async () =>
                {
                    var device = new CanvasDevice();
                    var rt = new CanvasRenderTarget(device, 16, 16, 96);

                    var filename = Path.Combine(ApplicationData.Current.TemporaryFolder.Path, "testfile.jpg");

                    await rt.SaveAsync(filename);

                    rt.Dispose();
                });

                task.Wait();
            }
        }
开发者ID:ben-sheeran,项目名称:Win2D,代码行数:28,代码来源:CanvasBitmapTests.cs


示例3: Save

        public async Task Save(StorageFile file)
        {
            var image = GetImage();

            // Measure the extent of the image (which may be cropped).
            Rect imageBounds;

            using (var commandList = new CanvasCommandList(sourceBitmap.Device))
            using (var drawingSession = commandList.CreateDrawingSession())
            {
                imageBounds = image.GetBounds(drawingSession);
            }

            // Rasterize the image into a rendertarget.
            using (var renderTarget = new CanvasRenderTarget(sourceBitmap.Device, (float)imageBounds.Width, (float)imageBounds.Height, 96))
            {
                using (var drawingSession = renderTarget.CreateDrawingSession())
                {
                    drawingSession.Blend = CanvasBlend.Copy;

                    drawingSession.DrawImage(image, -(float)imageBounds.X, -(float)imageBounds.Y);
                }

                // Save it out.
                var format = file.FileType.Equals(".png", StringComparison.OrdinalIgnoreCase) ? CanvasBitmapFileFormat.Png : CanvasBitmapFileFormat.Jpeg;

                using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))
                {
                    stream.Size = 0;

                    await renderTarget.SaveAsync(stream, format);
                }
            }
        }
开发者ID:shawnhar,项目名称:stuart,代码行数:34,代码来源:Photo.cs


示例4: mainCanvas_CreateResources

        async void mainCanvas_CreateResources(Microsoft.Graphics.Canvas.CanvasControl sender, object args)
        {
            m_isResourceLoadingDone = false;

            // WIN2D: resource loading from WinRT types including StorageFile and IRAS
            m_sourceBitmap = await CanvasBitmap.LoadAsync(sender, "Chrysanthemum.jpg");
            var sourceFile = await Package.Current.InstalledLocation.GetFileAsync("Chrysanthemum.jpg");

            // Win2D: because we can't lock/read pixels we rely on BitmapDecoder
            var stream = await sourceFile.OpenReadAsync();
            var decoder = await BitmapDecoder.CreateAsync(stream);

            // Technically these should always be identical to m_sourceBitmap.SizeInPixels;
            m_pixelArrayHeight = decoder.PixelHeight;
            m_pixelArrayWidth = decoder.PixelWidth;
            var pixelProvider = await decoder.GetPixelDataAsync(
                BitmapPixelFormat.Bgra8,
                BitmapAlphaMode.Premultiplied,
                new BitmapTransform(),
                ExifOrientationMode.IgnoreExifOrientation, // Must do this.
                ColorManagementMode.ColorManageToSRgb
                );

            m_pixelArray = pixelProvider.DetachPixelData();

            m_targetBitmap = new CanvasRenderTarget(sender, new Size(m_pixelArrayWidth, m_pixelArrayHeight));

            m_rnd = new Random();

            m_isResourceLoadingDone = true;

            mainCanvas.Invalidate();
        }
开发者ID:13thsymphony,项目名称:Toys,代码行数:33,代码来源:MainPage.xaml.cs


示例5: ToQrDataUri

    public async static Task<Uri> ToQrDataUri(this ISdp sdp, int width, int height)
    {
      var qrCodeWriter = new QRCodeWriter();
      var bitMatrix = qrCodeWriter.encode(sdp.ToString(), ZXing.BarcodeFormat.QR_CODE, width, height);

      using (var canvasRenderTarget = new CanvasRenderTarget(CanvasDevice.GetSharedDevice(), 500, 500, 96))
      {
        using (var drawingSession = canvasRenderTarget.CreateDrawingSession())
        {
          for (var y = 0; y < height; y++)
          {
            for (var x = 0; x < width; x++)
            {
              drawingSession.DrawRectangle(x, y, 1, 1, bitMatrix.get(x, y) ? Color.FromArgb(0, 0, 0, 0) : Color.FromArgb(255, 255, 255, 255));
            }
          }
        }

        using (var inMemoryRandomAccessStream = new InMemoryRandomAccessStream())
        {
          await canvasRenderTarget.SaveAsync(inMemoryRandomAccessStream, CanvasBitmapFileFormat.Png);
          inMemoryRandomAccessStream.Seek(0);
          var buffer = new byte[inMemoryRandomAccessStream.Size];
          await inMemoryRandomAccessStream.ReadAsync(buffer.AsBuffer(), (uint)inMemoryRandomAccessStream.Size, InputStreamOptions.None);
          return new Uri($"data:image/png;base64,{Convert.ToBase64String(buffer)}");
        }
      }
    }
开发者ID:Terricide,项目名称:TomasHubelbauer.WebRtcDataChannelsDotNet,代码行数:28,代码来源:ISdpExtensions.cs


示例6: ImageInfo

 public ImageInfo(CanvasRenderTarget image, Point offset, Rect symbolBounds, Rect imageBounds)
 {
     _crt = image;
     _offset = offset;
     _symbolBounds = symbolBounds;
     _imageBounds = imageBounds;
 }
开发者ID:michael-spinelli,项目名称:Renderer2525C-W10-UWP,代码行数:7,代码来源:ImageInfo.cs


示例7: CreateMap

        /// <summary>
        /// Создать карту.
        /// </summary>
        /// <param name="program">Программа.</param>
        /// <param name="width">Ширина.</param>
        /// <param name="fontSize">Размер шрифта.</param>
        /// <param name="maxLines">Максимальное число линий.</param>
        /// <returns>Карта.</returns>
        public ITextRender2MeasureMap CreateMap(ITextRender2RenderProgram program, double width, double fontSize, int? maxLines)
        {
            if (program == null) throw new ArgumentNullException(nameof(program));
            var interProgram = CreateIntermediateProgram(program).ToArray();
            var allText = interProgram.Aggregate(new StringBuilder(), (sb, s) => sb.Append(s.RenderString)).ToString();
            using (var tf = new CanvasTextFormat())
            {
                tf.FontFamily = "Segoe UI";
                tf.FontSize = (float)fontSize;
                tf.WordWrapping = CanvasWordWrapping.Wrap;
                tf.Direction = CanvasTextDirection.LeftToRightThenTopToBottom;
                tf.Options = CanvasDrawTextOptions.Default;

                var screen = DisplayInformation.GetForCurrentView();
                using (var ds = new CanvasRenderTarget(CanvasDevice.GetSharedDevice(), (float) width, 10f, screen.LogicalDpi))
                {
                    using (var tl = new CanvasTextLayout(ds, allText, tf, (float)width, 10f))
                    {
                        var helperArgs = interProgram.OfType<MappingHelperArg>().ToList();
                        mappingHelper.ApplyAttributes(tl, helperArgs, fontSize);
                        var map = AnalyzeMap(tl, allText).ToArray();
                        var result = new MeasureMap(map, width, maxLines, StrikethrougKoef);
                        return result;
                    }
                }
            }
        }
开发者ID:Opiumtm,项目名称:DvachBrowser3,代码行数:35,代码来源:Direct2dTextRender2MeasureMapper.cs


示例8: DrawStrokeOnImageBackground

		public byte[] DrawStrokeOnImageBackground(IReadOnlyList<InkStroke> strokes, byte[] backgroundImageBuffer)
		{

			var stmbuffer = new InMemoryRandomAccessStream();
			stmbuffer.AsStreamForWrite().AsOutputStream().WriteAsync(backgroundImageBuffer.AsBuffer()).AsTask().Wait();

			CanvasDevice device = CanvasDevice.GetSharedDevice();
			var canbit = CanvasBitmap.LoadAsync(device, stmbuffer, 96).AsTask().Result;


			CanvasRenderTarget renderTarget = new CanvasRenderTarget(device, canbit.SizeInPixels.Width, canbit.SizeInPixels.Height, 96);

			using (var ds = renderTarget.CreateDrawingSession())
			{
				ds.Clear(Colors.Transparent);

				if (backgroundImageBuffer != null)
				{

					ds.DrawImage(canbit);
				}

				ds.DrawInk(strokes);
			}
			var stm = new InMemoryRandomAccessStream();
			renderTarget.SaveAsync(stm, CanvasBitmapFileFormat.Png).AsTask().Wait();
			var readfrom = stm.GetInputStreamAt(0).AsStreamForRead();
			var ms = new MemoryStream();
			readfrom.CopyTo(ms);
			var outputBuffer = ms.ToArray();
			return outputBuffer;
		}
开发者ID:waynebaby,项目名称:GreaterShareUWP,代码行数:32,代码来源:DrawingService.cs


示例9: drawText

 public void drawText(CanvasRenderTarget crt, Color color)
 {
     using (CanvasDrawingSession ds = crt.CreateDrawingSession())
     {
         ds.DrawTextLayout(textLayout, (float)location.X, (float)location.Y, color);
     }
        
 }
开发者ID:michael-spinelli,项目名称:Renderer2525C-W10-UWP,代码行数:8,代码来源:TextInfo.cs


示例10: Process

 public void Process(CanvasBitmap input, CanvasRenderTarget output, TimeSpan time)
 {
     using (CanvasDrawingSession session = output.CreateDrawingSession())
     {
         session.DrawImage(input);
         session.DrawText("Canvas Effect test", 0f, 0f, Colors.Red);
     }
 }
开发者ID:gtarbell,项目名称:VideoEffect,代码行数:8,代码来源:Utils.cs


示例11: SSD1603

        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="config"></param>
        private SSD1603(SSD1603Configuration config, BusTypes bus)
        {
            Configuration = config;
            BusType = bus;

            //for drawing
            _canvasDevice = CanvasDevice.GetSharedDevice();
            Render = new CanvasRenderTarget(_canvasDevice,  Screen.WidthInDIP, Screen.HeightInDIP, Screen.DPI,
                            Windows.Graphics.DirectX.DirectXPixelFormat.A8UIntNormalized, CanvasAlphaMode.Straight);
        }
开发者ID:q-life,项目名称:Q.IoT,代码行数:14,代码来源:SSD1603.cs


示例12: BlurElementAsync

        /// <summary>
        /// Applys a blur to a UI element
        /// </summary>
        /// <param name="sourceElement">UIElement to blur, generally an Image control, but can be anything</param>
        /// <param name="blurAmount">Level of blur to apply</param>
        /// <returns>Blurred UIElement as BitmapImage</returns>
        public static async Task<BitmapImage> BlurElementAsync(this UIElement sourceElement, float blurAmount = 2.0f)
        {
            if (sourceElement == null)
                return null;

            var rtb = new RenderTargetBitmap();
            await rtb.RenderAsync(sourceElement);

            var buffer = await rtb.GetPixelsAsync();
            var array = buffer.ToArray();

            var displayInformation = DisplayInformation.GetForCurrentView();

            using (var stream = new InMemoryRandomAccessStream())
            {
                var pngEncoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);

                pngEncoder.SetPixelData(BitmapPixelFormat.Bgra8,
                                     BitmapAlphaMode.Premultiplied,
                                     (uint) rtb.PixelWidth,
                                     (uint) rtb.PixelHeight,
                                     displayInformation.RawDpiX,
                                     displayInformation.RawDpiY,
                                     array);

                await pngEncoder.FlushAsync();
                stream.Seek(0);

                var canvasDevice = new CanvasDevice();
                var bitmap = await CanvasBitmap.LoadAsync(canvasDevice, stream);

                var renderer = new CanvasRenderTarget(canvasDevice,
                                                      bitmap.SizeInPixels.Width,
                                                      bitmap.SizeInPixels.Height,
                                                      bitmap.Dpi);

                using (var ds = renderer.CreateDrawingSession())
                {
                    var blur = new GaussianBlurEffect
                    {
                        BlurAmount = blurAmount,
                        Source = bitmap
                    };
                    ds.DrawImage(blur);
                }

                stream.Seek(0);
                await renderer.SaveAsync(stream, CanvasBitmapFileFormat.Png);

                var image = new BitmapImage();
                await image.SetSourceAsync(stream);

                return image;
            }
        }
开发者ID:cheahengsoon,项目名称:UwpProjects,代码行数:61,代码来源:ExtensionMethods.cs


示例13: RenderTargetInheritsDpiFromResourceCreator

        public void RenderTargetInheritsDpiFromResourceCreator()
        {
            const float defaultDpi = 96;
            const float highDpi = 144;

            var device = new CanvasDevice();

            var renderTargetDefault = new CanvasRenderTarget(new TestResourceCreator(device, defaultDpi), 1, 1);
            var renderTargetHigh = new CanvasRenderTarget(new TestResourceCreator(device, highDpi), 1, 1);

            Assert.AreEqual(defaultDpi, renderTargetDefault.Dpi);
            Assert.AreEqual(highDpi, renderTargetHigh.Dpi);
        }
开发者ID:Himansh1306,项目名称:Win2D,代码行数:13,代码来源:DpiTests.cs


示例14: Process

 public void Process(CanvasBitmap input, CanvasRenderTarget output, TimeSpan time)
 {
     using (CanvasDrawingSession session = output.CreateDrawingSession())
     {
         session.DrawImage(input);
         session.FillCircle(
             (float)input.Bounds.Width / 2,
             (float)input.Bounds.Height / 2,
             (float)(Math.Min(input.Bounds.Width, input.Bounds.Height) / 2 * Math.Cos(2 * Math.PI * time.TotalSeconds)),
             Colors.Aqua
             );
     }
 }
开发者ID:gtarbell,项目名称:VideoEffect,代码行数:13,代码来源:CanvasEffect.cs


示例15: renderSVGPathToGraphics

        public void renderSVGPathToGraphics(CanvasRenderTarget crt)
        {
            /*
            //singlepoint graphic with absolute commands
            string path = "M1051 544L876 443L846 504L1018 600L1051 544ZM684 341L509 241L479 301L651 397L684 341ZM395 187L275 119L247 174L362 240L395 187ZM-833 -474L-1009 -568L-1038 -508L-864 -415L-833 -474ZM-237 -158L-411 -251L-439 -193L-271 -101L-237 -158ZM-533 -317L-709 -411L-739 -351L-567 -260L-533 -317ZM662 -399L514 -316L544 -263L690 -344L662 -399ZM-883 456L-1029 537L-999 592L-852 511L-883 456ZM992 -580L826 -488L859 -436L1021 -526L992 -580ZM-593 296L-748 382L-718 438L-566 350L-593 296ZM-305 137L-442 214L-415 268L-277 193L-305 137ZM381 -242L235 -161L272 -112L411 -188L381 -242ZM-210 -90L-111 -80Q-102 -130 -75 -153T-1 -176Q48 -176 73 -156T98 -107Q98 -89 88 -77T51 -55Q33 -49 -31 -33Q-112 -13 -145 17Q-191 58 -191 118Q-191 156 -170 189T-107 240T-8 258Q87 258 134 217T185 106L83 101Q77 140 56 157T-9 174Q-53 174 -78 156Q-94 144 -94 125Q-94 107 -79 94Q-60 78 14 61T123 25T179 -26T199 -107Q199 -150 175 -187T107 -243T-2 -262Q-98 -262 -149 -218T-210 -90Z";
            //singlepoint graphic with relative commands
            string pathLC = "M1051 544l-175 -101l-30 61l172 96zM684 341l-175 -100l-30 60l172 96zM395 187l-120 -68l-28 55l115 66zM-833 -474l-176 -94l-29 60l174 93zM-237 -158l-174 -93l-28 58l168 92zM-533 -317l-176 -94l-30 60l172 91zM662 -399l-148 83l30 53l146 -81zM-883 456l-146 81l30 55l147 -81zM992 -580l-166 92l33 52l162 -90zM-593 296l-155 86l30 56l152 -88zM-305 137l-137 77l27 54l138 -75zM381 -242l-146 81l37 49l139 -76zM-210 -90l98.999 10c6 -33.333 18.167 -57.666 36.5 -72.999s42.833 -23 73.5 -23c32.667 0 57.334 6.83301 74.001 20.5s25 29.834 25 48.501c0 12 -3.5 22.167 -10.5 30.5s-19.167 15.5 -36.5 21.5c-12 4 -39.333 11.333 -82 22c-54 13.333 -92 30 -114 50c-30.667 27.333 -46 61 -46 101c0 25.333 7.16699 49.166 21.5 71.499s35.166 39.333 62.499 51s60.333 17.5 99 17.5c63.333 0 110.833 -13.833 142.5 -41.5s48.5 -64.5 50.5 -110.5l-102 -5c-4 26 -13.167 44.667 -27.5 56s-35.833 17 -64.5 17c-29.333 0 -52.333 -6 -69 -18c-10.667 -8 -16 -18.333 -16 -31c0 -12 5 -22.333 15 -31c12.667 -10.667 43.667 -21.834 93 -33.501s85.833 -23.667 109.5 -36s42.167 -29.333 55.5 -51s20 -48.5 20 -80.5c0 -28.667 -8 -55.5 -24 -80.5s-38.667 -43.667 -68 -56s-65.666 -18.5 -108.999 -18.5c-64 0 -113 14.667 -147 44s-54.333 72 -61 128z";
            //the letter S
            string pathS = "M74 477L362 505Q388 360 467 292T682 224Q825 224 897 284T970 426Q970 478 940 514T833 578Q781 596 596 642Q358 701 262 787Q127 908 127 1082Q127 1194 190 1291T373 1440T662 1491Q938 1491 1077 1370T1224 1047L928 1034Q909 1147 847 1196T659 1246Q530 1246 457 1193Q410 1159 410 1102Q410 1050 454 1013Q510 966 726 915T1045 810T1207 661T1266 427Q1266 301 1196 191T998 28T679 -26Q401 -26 252 102T74 477Z";
            //air control point
            string pathACP = "M-355 354c-96.667 -97.333 -145 -215 -145 -353c0 -137.333 48.833 -254.666 146.5 -351.999s215.167 -146 352.5 -146c138 0 255.833 48.667 353.5 146s146.5 214.666 146.5 351.999c0 138 -48.5 255.667 -145.5 353s-215.167 146 -354.5 146 s-257.333 -48.667 -354 -146zM287.5 291c79.667 -80 119.498 -176.667 119.498 -290s-40.167 -210 -120.5 -290s-177.166 -120 -290.499 -120c-114 0 -211 40 -291 120s-120 176.667 -120 290s40 210 120 290s177 120 291 120c114.667 0 211.834 -40 291.501 -120zM-84.002 18h-47l-20 55h-89l-18 -55h-49l88 243h47zM-171.002 111l-29 86l-29 -86h58zM56.998 105l42.999 -15.999c-7.33301 -25.333 -18.666 -44.5 -33.999 -57.5s-34.333 -19.5 -57 -19.5c-29.333 0 -53.333 11 -72 33s-28 52 -28 90c0 40 9.66699 71.167 29 93.5 s44 33.5 74 33.5c26.667 0 48.334 -8.66699 65.001 -26c10 -10 17.667 -25 23 -45l-44 -12c-2.66699 13.333 -8.33398 23.666 -17.001 30.999s-18.334 11 -29.001 11c-16 0 -29 -6.66699 -39 -20s-15 -34 -15 -62c0 -30.667 4.83301 -52.667 14.5 -66s22.5 -20 38.5 -20 c10.667 0 20.334 4.33301 29.001 13s15 21.667 19 39zM126.997 18.001l0.000976562 242.998h72c27.333 0 45.333 -1.66699 54 -5c13.333 -2.66699 24.166 -10.167 32.499 -22.5s12.5 -28.166 12.5 -47.499c0 -15.333 -2.5 -28.166 -7.5 -38.499s-11.333 -18.333 -19 -24 s-15.5 -9.5 -23.5 -11.5c-10.667 -2 -26 -3 -46 -3h-30v-91h-45zM171.998 218.999v-68.999h25c18 0 30 1.16699 36 3.5s10.667 6.16602 14 11.499s5 12 5 20s-2.5 15 -7.5 21s-10.833 10 -17.5 12c-5.33301 0.666992 -16.333 1 -33 1h-22z";
            string AAMFrame = "M825 -750q-37 1143 -373 1519q-178 251 -452 281q-274 -30 -452 -283q-336 -374 -373 -1517h-129v168q9 1127 453 1560q248 228 501 232q253 -4 501 -232q444 -433 453 -1560v-168h-129z";
            string AAMFill = "M-866 -750q39 1200 391 1593q187 266 475 297q288 -31 475 -295q352 -395 391 -1595h-1732z";
            string AAMS1 = "M-182 -100h-88l-34 91h-162l-32 -91h-87l158 400h84zM-331 60l-57 145l-54 -145h111zM0 600l-110 -130v-745l-150 -95v-200l260 105l260 -105v200l-150 95v745zM588 -100h-88l-34 91h-162l-32 -91h-87l158 400h84zM439 60l-57 145l-54 -145h111zM70 440v-744l154 -89 v-122l-224 93l-224 -93v122l154 89v744l70 90z";
            string AAMS2 = "M70 440v-744l154 -89v-122l-224 93l-224 -93v122l154 89v744l70 90z";
            //string regex = 
            string[] parts = Regex.Split(path,_regex);

            foreach (String val in parts)
            {
                Debug.WriteLine(val);
            }
            Debug.WriteLine(_regex);

            SVGPath s = new SVGPath("0", pathACP);
            Color lineColor = (Colors.Black);
            Color fillColor = (Colors.Cyan);
            //Image foo = s.Draw(400,400,lineColor,fillColor);
            //g.DrawImage(foo, 200f, 200f);

            //Air to Air Missle test
            SVGPath sFill = new SVGPath("0",AAMFill);
            SVGPath sFrame = new SVGPath("0", AAMFrame);
            SVGPath sS1 = new SVGPath("0", AAMS1);
            SVGPath sS2 = new SVGPath("0", AAMS2);
            Image foo = sFrame.Draw(400, 400, lineColor, fillColor);
            crt.DrawImage(foo, 200f, 200f);

            //speed test
            int count = 1;
            Stopwatch sw = new Stopwatch();
            sw.Start();
            for(int k = 0; k < count; k++)
            {
                s = new SVGPath("0", path);
                s.Draw(60, 60, lineColor, fillColor);
            }
            sw.Stop();
            Debug.WriteLine("Rendered " + count.ToString() + " SP tactical graphics in " + Convert.ToString(sw.ElapsedMilliseconds / 1000.0) + " seconds.");
            //*/
        }
开发者ID:michael-spinelli,项目名称:Renderer2525C-W10-UWP,代码行数:51,代码来源:SVGRenderer.cs


示例16: MultithreadedSaveToStream

        public void MultithreadedSaveToStream()
        {
            // This is the stream version of the above test

            var task = Task.Run(async () =>
            {
                var device = new CanvasDevice();
                var rt = new CanvasRenderTarget(device, 16, 16, 96);

                var stream = new MemoryStream();
                await rt.SaveAsync(stream.AsRandomAccessStream(), CanvasBitmapFileFormat.Bmp);

                rt.Dispose();
            });

            task.Wait();
        }
开发者ID:RainbowGardens,项目名称:Win2D,代码行数:17,代码来源:CanvasBitmapTests.cs


示例17: CreateParticleBitmaps

        //Creates textures of different sizes
        public void CreateParticleBitmaps(bool blur = false)
        {
            SetColors(baseColor);

            particleBitmaps = new CanvasRenderTarget[sizes];

            int i = -1;
            var nextRadius = 0;
            var nextSize =0;
            var transparent = Color.FromArgb(0, 0, 0, 0);

            float viewportsize = 100; //Here is the trick, if this value is too small appears the displacement and the original image

            for (int r = 1; r < sizes + 1; r += 1)
            {
                nextRadius = (r * minRadius);
                nextSize = nextRadius * 2;
                CanvasRenderTarget canvas = new CanvasRenderTarget(device, viewportsize, viewportsize, parent.Dpi);
                var center = new Vector2((viewportsize - nextRadius) / 2);

                //The following is like a 'drawing graph', the output of the first is the input of the second one;
                using (CanvasDrawingSession targetSession = canvas.CreateDrawingSession())
                {
                    targetSession.Clear(transparent);
                    targetSession.FillCircle(center, nextRadius, outerColor);
                    targetSession.FillCircle(center, nextRadius - 6, innerColor);
                }

                if (!blur)
                {
                    particleBitmaps[++i] = canvas;
                }
                else //Add blur just one time
                {
                    var blurEffect = new GaussianBlurEffect() { BlurAmount = 2f };
                    CanvasRenderTarget blurredcanvas = new CanvasRenderTarget(device, viewportsize, viewportsize, parent.Dpi);
                    blurEffect.Source = canvas;
                    using (CanvasDrawingSession targetSession = blurredcanvas.CreateDrawingSession())
                    {
                        targetSession.Clear(transparent);
                        targetSession.DrawImage(blurEffect);
                    }
                    particleBitmaps[++i] = blurredcanvas;
                }
            }
        }
开发者ID:juanpaexpedite,项目名称:MasterDetailsComposition,代码行数:47,代码来源:ParticlesManager.cs


示例18: RenderTargetDpiTest

        public void RenderTargetDpiTest()
        {
            const float defaultDpi = 96;
            const float highDpi = defaultDpi * 2;
            const float size = 100;
            const float fractionalSize = 100.8f;

            var device = new CanvasDevice();

            var renderTargetDefault = new CanvasRenderTarget(device, size, size, defaultDpi);
            var renderTargetHigh = new CanvasRenderTarget(device, size, size, highDpi);
            var renderTargetFractionalSize = new CanvasRenderTarget(device, fractionalSize, fractionalSize, highDpi);

            // Check each rendertarget reports the expected DPI.
            Assert.AreEqual(defaultDpi, renderTargetDefault.Dpi);
            Assert.AreEqual(highDpi, renderTargetHigh.Dpi);
            Assert.AreEqual(highDpi, renderTargetFractionalSize.Dpi);

            // Check each rendertarget is of the expected size.
            Assert.AreEqual(size, renderTargetDefault.Size.Width);
            Assert.AreEqual(size, renderTargetDefault.Size.Height);

            Assert.AreEqual(size, renderTargetHigh.Size.Width);
            Assert.AreEqual(size, renderTargetHigh.Size.Height);

            Assert.AreEqual(Math.Round(fractionalSize), renderTargetFractionalSize.Size.Width);
            Assert.AreEqual(Math.Round(fractionalSize), renderTargetFractionalSize.Size.Height);

            // Check sizes in pixels.
            Assert.AreEqual(size, renderTargetDefault.SizeInPixels.Width);
            Assert.AreEqual(size, renderTargetDefault.SizeInPixels.Height);

            Assert.AreEqual(size * highDpi / defaultDpi, renderTargetHigh.SizeInPixels.Width);
            Assert.AreEqual(size * highDpi / defaultDpi, renderTargetHigh.SizeInPixels.Height);

            Assert.AreEqual(Math.Round(fractionalSize * highDpi / defaultDpi), renderTargetFractionalSize.SizeInPixels.Width);
            Assert.AreEqual(Math.Round(fractionalSize * highDpi / defaultDpi), renderTargetFractionalSize.SizeInPixels.Height);

            // Check that drawing sessions inherit the DPI of the rendertarget being drawn onto.
            var drawingSessionDefault = renderTargetDefault.CreateDrawingSession();
            var drawingSessionHigh = renderTargetHigh.CreateDrawingSession();

            Assert.AreEqual(defaultDpi, drawingSessionDefault.Dpi);
            Assert.AreEqual(highDpi, drawingSessionHigh.Dpi);
        }
开发者ID:Himansh1306,项目名称:Win2D,代码行数:45,代码来源:DpiTests.cs


示例19: Cache

        public ICanvasImage Cache(Photo photo, ICanvasImage image, params object[] keys)
        {
            if (cachedImage == null)
            {
                cachedImage = new CanvasRenderTarget(photo.SourceBitmap.Device, photo.Size.X, photo.Size.Y, 96);
            }

            using (var drawingSession = cachedImage.CreateDrawingSession())
            {
                drawingSession.Blend = CanvasBlend.Copy;
                drawingSession.DrawImage(image);
            }

            isCacheValid = true;
            cacheKeys = keys;

            return cachedImage;
        }
开发者ID:shawnhar,项目名称:stuart,代码行数:18,代码来源:CachedImage.cs


示例20: DrawStrokeOnSolidColorBackground

		public byte[] DrawStrokeOnSolidColorBackground(IReadOnlyList<InkStroke> strokes, int width, int height, Color color )
		{														 
			CanvasDevice device = CanvasDevice.GetSharedDevice();
			CanvasRenderTarget renderTarget = new CanvasRenderTarget(device, width, height, 96);

			using (var ds = renderTarget.CreateDrawingSession())
			{
				ds.Clear(color);
				ds.DrawInk(strokes);
			}
			var stm = new InMemoryRandomAccessStream();
			renderTarget.SaveAsync(stm, CanvasBitmapFileFormat.Png).AsTask().Wait();
			var readfrom = stm.GetInputStreamAt(0).AsStreamForRead();
			var ms = new MemoryStream();
			readfrom.CopyTo(ms);
			var outputBuffer = ms.ToArray();
			return outputBuffer;
		}
开发者ID:waynebaby,项目名称:GreaterShareUWP,代码行数:18,代码来源:DrawingService.cs



注:本文中的CanvasRenderTarget类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Capo类代码示例发布时间:2022-05-24
下一篇:
C# CanvasDevice类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap