當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。