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

C# CanvasDevice类代码示例

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

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



CanvasDevice类属于命名空间,在下文中一共展示了CanvasDevice类的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: 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


示例16: Initialize

        static public void Initialize(Compositor compositor)
        {
            Debug.Assert(!_intialized);

            _compositor = compositor;
            _canvasDevice = new CanvasDevice();
            _compositionDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _canvasDevice);

            _intialized = true;
        }
开发者ID:punker76,项目名称:composition,代码行数:10,代码来源:SurfaceLoader.cs


示例17: win2d_Button

        public win2d_Button(CanvasDevice device, Vector2 position, int width, int height, string text)
            : base(position, width, height)
        {
            ButtonRectangle = new Rect(Position.X, Position.Y, Width, Height);

            TextLayout = new CanvasTextLayout(device, text, Statics.DefaultFontNoWrap, 0, 0);
            TextLayoutPosition = new Vector2(Position.X + (Width - (float)TextLayout.LayoutBounds.Width) / 2, Position.Y + (Height - (float)TextLayout.LayoutBounds.Height) / 2);

            Color = Colors.Gray;
        }
开发者ID:flameeyez,项目名称:win2d_text_game,代码行数:10,代码来源:win2d_Button.cs


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


示例19: TestBitmapPixelFormats

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

            foreach (var format in AllPixelFormats())
            {
                // Unknown formats should not be supported.
                if (!formatFlags.ContainsKey(format))
                {
                    Assert.IsFalse(device.IsPixelFormatSupported(format));
                    ValidateCannotCreateBitmap(device, format, FirstSupportedAlphaMode(format));
                    continue;
                }

                // Optional formats may be legitimately not supported, depending on the device.
                if (!device.IsPixelFormatSupported(format))
                {
                    Assert.IsTrue((formatFlags[format] & FormatFlags.Optional) != 0);
                    ValidateCannotCreateBitmap(device, format, FirstSupportedAlphaMode(format));
                    continue;
                }

                // We should be able to create this format using all its supported alpha modes.
                var lotsOfZeroes = new byte[1024];

                foreach (var alphaMode in SupportedAlphaModes(format))
                {
                    CanvasBitmap.CreateFromBytes(device, lotsOfZeroes, 4, 4, format, 96, alphaMode);
                }

                // Other alpha modes should not be supported.
                foreach (var alphaMode in UnsupportedAlphaModes(format))
                {
                    ValidateCannotCreateBitmap(device, format, alphaMode);
                }

                // We should also be able to create this format without explicitly specifying an alpha mode.
                var bitmap = CanvasBitmap.CreateFromBytes(device, lotsOfZeroes, 4, 4, format);

                Assert.AreEqual(FirstSupportedAlphaMode(format), bitmap.AlphaMode);

                // Some formats can be drawn directly, while others cannot.
                if ((formatFlags[format] & FormatFlags.CannotDraw) == 0)
                {
                    ValidateCanDrawImage(device, bitmap);
                }
                else
                {
                    ValidateCannotDrawImage(device, bitmap);
                }

                // But all formats should be drawable when used as effect inputs.
                ValidateCanDrawImage(device, new ColorMatrixEffect { Source = bitmap });
            }
        }
开发者ID:thepepor,项目名称:Win2D,代码行数:55,代码来源:PixelFormatTests.cs


示例20: Add

        public void Add(CanvasDevice device, string str)
        {
            win2d_TextblockString s = new win2d_TextblockString(device, str, DrawingWidth);
            Strings.Add(s);
            _totalstringsheight += s.Height + StringPaddingY;

            if(ScrollToBottomOnAppend)
            {
                ScrollToBottom();
            }
        }
开发者ID:flameeyez,项目名称:win2d_text_game,代码行数:11,代码来源:win2d_TextblockStringCollection.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# CanvasRenderTarget类代码示例发布时间:2022-05-24
下一篇:
C# CanvasControl类代码示例发布时间: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