当前位置: 首页>>代码示例>>C#>>正文


C# CanvasDevice类代码示例

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


CanvasDevice类属于命名空间,在下文中一共展示了CanvasDevice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: RichListBox

        public RichListBox(CanvasDevice device, Vector2 position, int width, int height, string title, CanvasTextFormat titleFont, CanvasTextFormat stringsFont, int maxStrings = 0)
        {
            // base(device, position, width, 0, title, titleFont)
            Position = position;

            // title
            Title = new CanvasTextLayout(device, title, titleFont, 0, 0);
            TitlePosition = new Vector2(Position.X + Padding, Position.Y + Padding);

            // width is derived from title bounds
            Width = width;  //(int)Title.LayoutBounds.Width + Padding * 2;
            Height = height;

            // bar under title
            BarUnderTitleLeft = new Vector2(Position.X, Position.Y + Padding * 2 + (float)Title.LayoutBounds.Height);
            BarUnderTitleRight = new Vector2(Position.X + Width, Position.Y + Padding * 2 + (float)Title.LayoutBounds.Height);

            // strings
            StringsFont = stringsFont;
            StringsTextLayout = new CanvasTextLayout(device, "THIS IS A PRETTY GOOD TEMP STRING", StringsFont, 0, 0);
            StringsPosition = new Vector2(Position.X + Padding, BarUnderTitleRight.Y + Padding);

            MaxStrings = maxStrings == 0 ? 1000 : maxStrings;

            BorderRectangle = new Rect(Position.X, Position.Y, Width, Height);
        }
开发者ID:flameeyez,项目名称:Win2D_BattleRoyale,代码行数:26,代码来源:RichListBox.cs

示例3: Create

        public static World Create(CanvasDevice device, int widthInTiles, int heightInTiles, IProgress<Tuple<string, float>> progress)
        {
            World world = new World();

            ProtoWorld pw = new ProtoWorld(device, widthInTiles, heightInTiles, progress);
            while (pw.Aborted) { pw = new ProtoWorld(device, widthInTiles, heightInTiles, progress); }

            world.Width = pw.Width;
            world.Height = pw.Height;
            foreach (ProtoRegion pr in pw.ProtoRegions)
            {
                world.Regions.Add(Region.FromProtoRegion(pr));
            }

            foreach (ProtoRegion pcr in pw.ProtoCaves)
            {
                world.Caves.Add(Region.FromProtoRegion(pcr));
            }

            world.RenderTargetRegions = pw.RenderTargetRegions;
            world.RenderTargetSubregions = pw.RenderTargetSubregions;
            world.RenderTargetPaths = pw.RenderTargetPaths;
            world.RenderTargetHeightMap = pw.RenderTargetHeightMap;
            world.RenderTargetCaves = pw.RenderTargetCaves;
            world.RenderTargetCavePaths = pw.RenderTargetCavePaths;

            return world;
        }
开发者ID:flameeyez,项目名称:win2d_text_game_world_generator,代码行数:28,代码来源:World.cs

示例4: Append

 public void Append(CanvasDevice device, string str)
 {
     lock (Strings)
     {
         Strings.Add(device, str);
     }
 }
开发者ID:flameeyez,项目名称:win2d_text_game,代码行数:7,代码来源:win2d_Textblock.cs

示例5: Run

        public void Run(IBackgroundTaskInstance taskInstance)
        {
            using (device = new CanvasDevice())
            {
                try
                {
                    GenerateTileImage(TileTemplateType.TileSquare150x150Image, 150, 150);
                    GenerateTileImage(TileTemplateType.TileWide310x150Image, 310, 150);
                }
                catch (Exception e)
                {
                    if (device.IsDeviceLost(e.HResult))
                    {
                        // When the device is lost we don't attempt to retry, and instead just wait for
                        // the next time the task runs.
                        return;
                    }

                    // Any other errors we bubble up
                    throw;
                }
            }

            UpdateLiveTiles();
            DeleteOldLiveTileImageFiles();
            LiveTileUpdater.SetLatestTileImagesInSettings(tiles.Values);
        }
开发者ID:jiatingxiu,项目名称:Win2D,代码行数:27,代码来源:LiveTileUpdaterTask.cs

示例6: win2d_TextboxCursor

        public win2d_TextboxCursor(CanvasDevice device, Color color)
        {
            Color = color;
            LastUpdate = TimeSpan.Zero;

            CursorCharacter = new CanvasTextLayout(device, "|", Statics.DefaultFontNoWrap, 0, 0);
        }
开发者ID:flameeyez,项目名称:win2d_text_game_world_generator,代码行数:7,代码来源:win2d_TextboxCursor.cs

示例7: win2d_Button

 public win2d_Button(CanvasDevice device, Vector2 position, int width, int height, string text)
     : base(position, width, height)
 {
     Color = Colors.Gray;
     TextLayout = new CanvasTextLayout(device, text, Statics.DefaultFontNoWrap, 0, 0);
     RecalculateLayout();
 }
开发者ID:flameeyez,项目名称:win2d_text_game_world_generator,代码行数:7,代码来源:win2d_Button.cs

示例8: 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

示例9: win2d_TextblockStringCollection

 public win2d_TextblockStringCollection(CanvasDevice device, Vector2 position, int drawingwidth, int drawingheight, bool scrolltobottomonappend = false)
 {
     _device = device;
     Position = position;
     DrawingWidth = drawingwidth;
     DrawingHeight = drawingheight;
     ScrollToBottomOnAppend = scrolltobottomonappend;
 }
开发者ID:flameeyez,项目名称:win2d_text_game_world_generator,代码行数:8,代码来源:win2d_TextblockStringCollection.cs

示例10: CreateResources

        private void CreateResources(Size sizeSwapchain)
        {
            _device = new CanvasDevice();
            _swapchain = new CanvasSwapChain(_device, (float)sizeSwapchain.Width, (float)sizeSwapchain.Height, 96);

            // Start rendering the swapchain
            StartRendering(sizeSwapchain);
        }
开发者ID:clarkezone,项目名称:BUILD2015-Talk-2-672,代码行数:8,代码来源:MainPage.xaml.cs

示例11: CreateFromBuffer

        public void CreateFromBuffer()
        {
            var device = new CanvasDevice();

            byte[] somePixelData = { 1, 2, 3, 4 };

            var buffer = somePixelData.AsBuffer();

            // Overload #1
            var bitmap = CanvasBitmap.CreateFromBytes(device, buffer, 2, 2, DirectXPixelFormat.A8UIntNormalized);

            Assert.AreEqual(2u, bitmap.SizeInPixels.Width);
            Assert.AreEqual(2u, bitmap.SizeInPixels.Height);
            Assert.AreEqual(96, bitmap.Dpi);
            Assert.AreEqual(DirectXPixelFormat.A8UIntNormalized, bitmap.Format);
            Assert.AreEqual(CanvasAlphaMode.Premultiplied, bitmap.AlphaMode);

            CollectionAssert.AreEqual(somePixelData, bitmap.GetPixelBytes());

            // Overload #2
            const float someDpi = 123.0f;

            bitmap = CanvasBitmap.CreateFromBytes(device, buffer, 2, 2, DirectXPixelFormat.A8UIntNormalized, someDpi);

            Assert.AreEqual(2u, bitmap.SizeInPixels.Width);
            Assert.AreEqual(2u, bitmap.SizeInPixels.Height);
            Assert.AreEqual(someDpi, bitmap.Dpi);
            Assert.AreEqual(DirectXPixelFormat.A8UIntNormalized, bitmap.Format);
            Assert.AreEqual(CanvasAlphaMode.Premultiplied, bitmap.AlphaMode);

            CollectionAssert.AreEqual(somePixelData, bitmap.GetPixelBytes());

            // Overload #3
            bitmap = CanvasBitmap.CreateFromBytes(device, buffer, 2, 2, DirectXPixelFormat.A8UIntNormalized, someDpi, CanvasAlphaMode.Straight);

            Assert.AreEqual(2u, bitmap.SizeInPixels.Width);
            Assert.AreEqual(2u, bitmap.SizeInPixels.Height);
            Assert.AreEqual(someDpi, bitmap.Dpi);
            Assert.AreEqual(DirectXPixelFormat.A8UIntNormalized, bitmap.Format);
            Assert.AreEqual(CanvasAlphaMode.Straight, bitmap.AlphaMode);

            CollectionAssert.AreEqual(somePixelData, bitmap.GetPixelBytes());

            // Null device.
            Assert.ThrowsException<ArgumentException>(() => CanvasBitmap.CreateFromBytes(null, buffer, 2, 2, DirectXPixelFormat.A8UIntNormalized));
            Assert.ThrowsException<ArgumentException>(() => CanvasBitmap.CreateFromBytes(null, buffer, 2, 2, DirectXPixelFormat.A8UIntNormalized, someDpi));
            Assert.ThrowsException<ArgumentException>(() => CanvasBitmap.CreateFromBytes(null, buffer, 2, 2, DirectXPixelFormat.A8UIntNormalized, someDpi, CanvasAlphaMode.Straight));

            // Null buffer.
            IBuffer nullBuffer = null;

            Assert.ThrowsException<ArgumentException>(() => CanvasBitmap.CreateFromBytes(device, nullBuffer, 2, 2, DirectXPixelFormat.A8UIntNormalized));
            Assert.ThrowsException<ArgumentException>(() => CanvasBitmap.CreateFromBytes(device, nullBuffer, 2, 2, DirectXPixelFormat.A8UIntNormalized, someDpi));
            Assert.ThrowsException<ArgumentException>(() => CanvasBitmap.CreateFromBytes(device, nullBuffer, 2, 2, DirectXPixelFormat.A8UIntNormalized, someDpi, CanvasAlphaMode.Straight));

            // Too small a buffer.
            Assert.ThrowsException<ArgumentException>(() => CanvasBitmap.CreateFromBytes(device, buffer, 3, 3, DirectXPixelFormat.A8UIntNormalized));
        }
开发者ID:ben-sheeran,项目名称:Win2D,代码行数:58,代码来源:CanvasBitmapTests.cs

示例12: Initialize

        public static void Initialize(CanvasDevice device)
        {
            LoadCharacterWidths(device);

            UpArrow = new CanvasTextLayout(device, "\u2191", Statics.DefaultFontNoWrap, 0, 0);
            DoubleUpArrow = new CanvasTextLayout(device, "\u219f", Statics.DefaultFontNoWrap, 0, 0);
            DownArrow = new CanvasTextLayout(device, "\u2193", Statics.DefaultFontNoWrap, 0, 0);
            DoubleDownArrow = new CanvasTextLayout(device, "\u21a1", Statics.DefaultFontNoWrap, 0, 0);
        }
开发者ID:flameeyez,项目名称:win2d_text_game,代码行数:9,代码来源:Statics.cs

示例13: FeedItemLayoutData

 public FeedItemLayoutData(CanvasDevice device, FeedItem feedItem, float fRequestedWidth)
 {
     FeedDataTitleLayout = new CanvasTextLayout(device, feedItem.FeedDataTitle, Statics.DefaultFont, fRequestedWidth, 20);
     PublicationDateLayout = new CanvasTextLayout(device, feedItem.PublicationDate.ToString("MM/dd/yy"), Statics.DefaultFont, fRequestedWidth, 20); // MMMM dd, yyyy - h:mm
     TitleLayout = new CanvasTextLayout(device, feedItem.Title, Statics.DefaultFont, fRequestedWidth, 20);
     AuthorLayout = new CanvasTextLayout(device, feedItem.Author, Statics.DefaultFont, fRequestedWidth, 20);
     if (feedItem.Title != feedItem.Content) { ContentLayout = new CanvasTextLayout(device, feedItem.Content, Statics.DefaultFont, fRequestedWidth, 20); }
     LinkLayout = new CanvasTextLayout(device, feedItem.Link.ToString(), Statics.DefaultFont, fRequestedWidth, 20);
 }
开发者ID:flameeyez,项目名称:win2d_rss,代码行数:9,代码来源:FeedItemLayoutData.cs

示例14: win2d_Textblock

 public win2d_Textblock(CanvasDevice device, Vector2 position, int width, int height, bool scrolltobottomonappend = false)
     : base(position, width, height)
 {
     _device = device;
     Strings = new win2d_TextblockStringCollection(_device, new Vector2(Position.X + PaddingX, Position.Y + PaddingY),
                                                     Width - PaddingY * 2,
                                                     Height - PaddingY * 2,
                                                     scrolltobottomonappend);
 }
开发者ID:flameeyez,项目名称:win2d_text_game_world_generator,代码行数:9,代码来源:win2d_Textblock.cs

示例15: 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


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