示例#1
0
        void DrawDrawingSurface()
        {
            ++drawCount;

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

                var rect = new Rect(new Point(2, 2), (drawingSurface.Size.ToVector2() - new Vector2(4, 4)).ToSize());

                ds.FillRoundedRectangle(rect, 15, 15, Colors.LightBlue);
                ds.DrawRoundedRectangle(rect, 15, 15, Colors.Gray, 2);

                ds.DrawText("This is a composition drawing surface", rect, Colors.Black, new CanvasTextFormat()
                {
                    FontFamily          = "Comic Sans MS",
                    FontSize            = 32,
                    WordWrapping        = CanvasWordWrapping.WholeWord,
                    VerticalAlignment   = CanvasVerticalAlignment.Center,
                    HorizontalAlignment = CanvasHorizontalAlignment.Center
                });

                ds.DrawText("Draws: " + drawCount, rect, Colors.Black, new CanvasTextFormat()
                {
                    FontSize            = 10,
                    VerticalAlignment   = CanvasVerticalAlignment.Bottom,
                    HorizontalAlignment = CanvasHorizontalAlignment.Center
                });
            }
        }
示例#2
0
#pragma warning disable 1998
        public async Task Draw(CompositionGraphicsDevice device, Object drawingLock, CompositionDrawingSurface surface, Size size)
        {
            using (var ds = CanvasComposition.CreateDrawingSession(surface)) {
                ds.Clear(Colors.Transparent);
                ds.FillCircle(new Vector2(_radius, _radius), _radius, _color);
            }
        }
        CompositionDrawingSurface ApplyBlurEffect(CanvasBitmap bitmap, Windows.UI.Composition.CompositionGraphicsDevice device, Size sizeTarget)
        {
            GaussianBlurEffect blurEffect = new GaussianBlurEffect()
            {
                Source     = bitmap,
                BlurAmount = 20.0f,
                BorderMode = EffectBorderMode.Hard,
            };

            float fDownsample = .3f;
            Size  sizeSource  = bitmap.Size;

            if (sizeTarget == Size.Empty)
            {
                sizeTarget = sizeSource;
            }

            sizeTarget = new Size(sizeTarget.Width * fDownsample, sizeTarget.Height * fDownsample);
            CompositionDrawingSurface blurSurface = device.CreateDrawingSurface(sizeTarget, DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied);

            using (var ds = CanvasComposition.CreateDrawingSession(blurSurface))
            {
                Rect destination = new Rect(0, 0, sizeTarget.Width, sizeTarget.Height);
                ds.Clear(Windows.UI.Color.FromArgb(255, 255, 255, 255));
                ds.DrawImage(blurEffect, destination, new Rect(0, 0, sizeSource.Width, sizeSource.Height));
            }

            return(blurSurface);
        }
 /// <summary>
 /// Redraws the mask surface with the given size and geometry
 /// </summary>
 /// <param name="surface">CompositionDrawingSurface</param>
 /// <param name="size">Size ofthe Mask Surface</param>
 /// <param name="geometry">Geometry of the Mask Surface</param>
 /// <returns>Task</returns>
 public Task RedrawMaskSurfaceAsync(CompositionDrawingSurface surface, Size size, CanvasGeometry geometry)
 {
     return(Task.Run(() =>
     {
         //
         // Since the drawing is done asynchronously and multiple threads could
         // be trying to get access to the device/surface at the same time, we need
         // to do any device/surface work under a lock.
         //
         lock (_drawingLock)
         {
             // Render the mask to the surface
             using (var session = CanvasComposition.CreateDrawingSession(surface))
             {
                 // If the geometry is not null then fill the geometry area
                 // with white. The rest of the area on the surface will be transparent.
                 // When this mask is applied to a visual, only the area that is white
                 // will be visible.
                 if (geometry != null)
                 {
                     session.Clear(Colors.Transparent);
                     session.FillGeometry(geometry, Colors.White);
                 }
                 else
                 {
                     // If the geometry is null, then the entire mask should be filled white
                     // so that the masked visual can be seen completely.
                     session.Clear(Colors.White);
                 }
             }
         }
     }));
 }
示例#5
0
 void RenderFrame()
 {
     if (destinationTarget != null)
     {
         lock (ResourceLock)
         {
             var args = new VideoEffectHandlerArgs()
             {
                 InputFrame  = sourceTarget,
                 OutputFrame = destinationTarget,
                 ID          = ID,
                 Properties  = Properties,
                 Device      = CanvasDevice
             };
             bool effectsAdded = VideoEffectManager.ProcessFrame(args);
             using (var ds = CanvasComposition.CreateDrawingSession(DrawingSurface))
             {
                 ds.DrawImage(destinationTarget);
             }
         }
     }
     else
     {
         Container.RunOnUIThread(createDestinationTarget);
     }
 }
示例#6
0
 public async Task Draw(CompositionGraphicsDevice device, Object drawingLock, CompositionDrawingSurface surface, Size size)
 {
     using (var ds = CanvasComposition.CreateDrawingSession(surface)) {
         ds.Clear(_backgroundColor);
         ds.DrawText(_text, new Rect(0, 0, surface.Size.Width, surface.Size.Height), _textColor, _textFormat);
     }
 }
示例#7
0
        public void DrawString(string c)
        {
            sofar += c;
            using (
                var drawingSession = CanvasComposition.CreateDrawingSession(drawingSurface,
                                                                            new Rect(0, 0, ActualWidth, ActualHeight)))
            {
                CanvasTextFormat tf = new CanvasTextFormat()
                {
                    FontSize = 72
                };

                float            xLoc   = 100.0f;
                float            yLoc   = 100.0f;
                CanvasTextFormat format = new CanvasTextFormat
                {
                    FontSize     = 30.0f,
                    WordWrapping = CanvasWordWrapping.NoWrap
                };
                CanvasTextLayout textLayout = new CanvasTextLayout(drawingSession, sofar, format, 0.0f,
                                                                   0.0f);
                Rect theRectYouAreLookingFor = new Rect(xLoc + textLayout.DrawBounds.X,
                                                        yLoc + textLayout.DrawBounds.Y, textLayout.DrawBounds.Width, textLayout.DrawBounds.Height);
                drawingSession.DrawRectangle(theRectYouAreLookingFor, Colors.Green, 1.0f);
                drawingSession.DrawTextLayout(textLayout, xLoc, yLoc, Colors.Yellow);

                drawingSession.DrawInk(list);
            }
        }
示例#8
0
        void DrawText(CanvasTextLayout textLayout)
        {
            #region unused
            // text drawer method 1 - no anti-aliasing feature
            //var layout = new CanvasTextLayout(_device, Text, textformat, (float)Width, (float)Height);
            //var geometry = CanvasGeometry.CreateText(layout);
            //var compPath = new CompositionPath(geometry);
            //var pathGeo = _compositor.CreatePathGeometry(compPath);

            // set to container
            //var w = _compositor.CreateSpriteShape(pathGeo);
            //w.FillBrush = _compositor.CreateColorBrush(Color.FromArgb(0xd7, 0xff, 0xff, 0xff));
            //_shape.Shapes.Add(w);
            #endregion

            // text drawer - with anti-aliasing feature
            using var ds = CanvasComposition.CreateDrawingSession(_drawsurface);

            ds.Antialiasing = CanvasAntialiasing.Antialiased;
            //ds.DrawText(Text, rectext, Color.FromArgb(0xd7, 0xff, 0xff, 0xff), textformat);
            ds.DrawTextLayout(textLayout, (float)Width / 2, (float)Height / 2, Color.FromArgb(0xd7, 0xff, 0xff, 0xff));
            ds.Flush();
            ds.Dispose();

            // set to container
            var brush  = _compositor.CreateSurfaceBrush(_drawsurface);
            var sprite = _compositor.CreateSpriteVisual();
            sprite.Brush = brush;
            sprite.Size  = _size;
            _shape.Children.InsertAtTop(sprite);
        }
示例#9
0
        public async Task DrawSurface(CompositionDrawingSurface surface, Uri uri, Size size)
        {
            var canvasDevice = CanvasComposition.GetCanvasDevice(_graphicsDevice);

            using (var canvasBitmap = await CanvasBitmap.LoadAsync(canvasDevice, uri))
            {
                var bitmapSize = canvasBitmap.Size;

                //
                // Because the drawing is done asynchronously and multiple threads could
                // be trying to get access to the device/surface at the same time, we need
                // to do any device/surface work under a lock.
                //
                lock (_drawingLock)
                {
                    Size surfaceSize = size;
                    if (surfaceSize.IsEmpty)
                    {
                        // Resize the surface to the size of the image
                        CanvasComposition.Resize(surface, bitmapSize);
                        surfaceSize = bitmapSize;
                    }

                    // Draw the image to the surface
                    using (var session = CanvasComposition.CreateDrawingSession(surface))
                    {
                        session.Clear(Windows.UI.Color.FromArgb(0, 0, 0, 0));
                        session.DrawImage(canvasBitmap, new Rect(0, 0, surfaceSize.Width, surfaceSize.Height), new Rect(0, 0, bitmapSize.Width, bitmapSize.Height));
                    }
                }
            }
        }
示例#10
0
        internal void ReDraw(Rect viewPort, float zoom)
        {
            var toDraw = GetDrawingBoundaries(viewPort);
            var scale  = _screenScale * zoom;
            var rect   = ScaleRect(toDraw, scale);
            var dpi    = BaseCanvasDPI * (float)scale;

            try
            {
                using (var drawingSession = CanvasComposition.CreateDrawingSession(_drawingSurface, rect, dpi))
                {
                    drawingSession.Clear(Colors.White);
                    foreach (var drawable in _visibleList)
                    {
                        drawable.Draw(drawingSession, toDraw);
                    }
                }
            }
            catch (ArgumentException)
            {
                /* CanvasComposition.CreateDrawingSession has an internal
                 * limit on the size of the updateRectInPixels parameter,
                 * which we don't know, so we can get an ArgumentException
                 * if there is a lot of extreme zooming and panning
                 * Therefore, the only solution is to silently catch the
                 * exception and allow the app to continue
                 */
            }
        }
        public void DrawTile(Rect rect, int tileRow, int tileColumn)
        {
            Color waterColor = Color.FromArgb(255, 172, 199, 242);
            Action <CanvasBitmap> drawAction = (CanvasBitmap bitmap) =>
            {
                lock (sync)
                {
                    using (var drawingSession = CanvasComposition.CreateDrawingSession(drawingSurface, rect))
                    {
                        drawingSession.Clear(waterColor);
                        if (bitmap != null)
                        {
                            drawingSession.DrawImage(bitmap);
                        }
                    }
                }
            };

            if (TileCache.Tiles.ContainsKey(TileCache.GetTileKey(ZoomLevel, tileColumn, tileRow)))
            {
                drawAction(TileCache.Tiles[TileCache.GetTileKey(ZoomLevel, tileColumn, tileRow)]);
            }
            else
            {
                drawAction(null);

                //TODO handle the error case where the load fails
                CanvasBitmap.LoadAsync(CanvasDevice.GetSharedDevice(), TileCache.GetTileUri(ZoomLevel, tileColumn, tileRow), 96).AsTask().ContinueWith((bm) =>
                {
                    TileCache.AddImage(ZoomLevel, tileColumn, tileRow, bm.Result);
                    //redraw the tile once we have the image downloaded
                    drawAction(bm.Result);
                });
            }
        }
        private static async Task <CompositionDrawingSurface> GetCompositionDrawingSurface(Compositor compositor, RenderTargetBitmap renderTargetBitmap)
        {
            IBuffer pixels = await renderTargetBitmap.GetPixelsAsync();

            using (var canvasDevice = new CanvasDevice())
                using (CompositionGraphicsDevice graphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(compositor, canvasDevice))
                {
                    float dpi = DisplayInformation.GetForCurrentView().LogicalDpi;
                    using (var canvasBitmap = CanvasBitmap.CreateFromBytes(canvasDevice, pixels.ToArray(),
                                                                           renderTargetBitmap.PixelWidth, renderTargetBitmap.PixelHeight,
                                                                           DirectXPixelFormat.B8G8R8A8UIntNormalized, dpi))
                    {
                        CompositionDrawingSurface surface = graphicsDevice.CreateDrawingSurface(
                            new Size(renderTargetBitmap.PixelWidth, renderTargetBitmap.PixelHeight),
                            DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied);
                        using (CanvasDrawingSession session = CanvasComposition.CreateDrawingSession(surface))
                        {
                            session.DrawImage(canvasBitmap, 0, 0,
                                              new Rect(0, 0, canvasBitmap.Size.Width, canvasBitmap.Size.Height));
                        }

                        return(surface);
                    }
                }
        }
        /// <summary>
        /// Initializes the Composition Brush.
        /// </summary>
        protected override void OnConnected()
        {
            base.OnConnected();

            // Delay creating composition resources until they're required.
            if (CompositionBrush == null)
            {
                // Abort if effects aren't supported.
                if (!CompositionCapabilities.GetForCurrentView().AreEffectsSupported())
                {
                    return;
                }

                var size = new Vector2(SurfaceWidth, SurfaceHeight);

                var device   = CanvasDevice.GetSharedDevice();
                var graphics = CanvasComposition.CreateCompositionGraphicsDevice(Window.Current.Compositor, device);

                var surface = graphics.CreateDrawingSurface(size.ToSize(), DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied);

                using (var session = CanvasComposition.CreateDrawingSession(surface))
                {
                    // Call Implementor to draw on session.
                    if (!OnDraw(device, session, size))
                    {
                        return;
                    }
                }

                _surfaceBrush         = Window.Current.Compositor.CreateSurfaceBrush(surface);
                _surfaceBrush.Stretch = CompositionStretch.Fill;

                CompositionBrush = _surfaceBrush;
            }
        }
示例#14
0
        /// <summary>
        ///     This method allows us to reuse a background image that has already been processed.
        /// </summary>
        /// <param name="pixels">The pixel buffer.</param>
        /// <param name="bitmap">The output from RenderTargetBitmap.</param>
        /// <param name="dpi">The view DPI where the background was rendered.</param>
        /// <param name="areaToRender">The region of the background we wish to cut out.</param>
        /// <returns>A <see cref="CompositionSurfaceBrush" /> containing the portion of the background we want.</returns>
        private CompositionSurfaceBrush CreateBackgroundBrush(IBuffer pixels, RenderTargetBitmap bitmap, float dpi,
                                                              Rect areaToRender)
        {
            // load the pixels from RenderTargetBitmap onto a CompositionDrawingSurface
            CompositionDrawingSurface uiElementBitmapSurface;

            using (
                // this is the entire background image
                // Note we are using the display DPI here.
                var canvasBitmap = CanvasBitmap.CreateFromBytes(
                    _canvasDevice, pixels.ToArray(),
                    bitmap.PixelWidth,
                    bitmap.PixelHeight,
                    DirectXPixelFormat.B8G8R8A8UIntNormalized,
                    dpi)
                )
            {
                // we create a surface we can draw on in memory.
                // note we are using the desired size of our overlay
                uiElementBitmapSurface =
                    _compositionDevice.CreateDrawingSurface(
                        new Size(areaToRender.Width, areaToRender.Height),
                        DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied);
                using (var session = CanvasComposition.CreateDrawingSession(uiElementBitmapSurface))
                {
                    // here we draw just the part of the background image we wish to use to overlay
                    session.DrawImage(canvasBitmap, 0, 0, areaToRender);
                }
            }

            var backgroundBrush = _compositor.CreateSurfaceBrush(uiElementBitmapSurface);

            backgroundBrush.Stretch = CompositionStretch.UniformToFill;
            return(backgroundBrush);
        }
        private static async Task <CompositionDrawingSurface> LoadFromUri(CanvasDevice canvasDevice, CompositionGraphicsDevice compositionDevice, Uri uri, Size sizeTarget)
        {
            CanvasBitmap bitmap = await CanvasBitmap.LoadAsync(canvasDevice, uri);

            Size sizeSource = bitmap.Size;

            if (sizeTarget.IsEmpty)
            {
                sizeTarget = sizeSource;
            }

            var surface = compositionDevice.CreateDrawingSurface(
                sizeTarget,
                DirectXPixelFormat.B8G8R8A8UIntNormalized,
                DirectXAlphaMode.Premultiplied);

            using (var ds = CanvasComposition.CreateDrawingSession(surface))
            {
                ds.Clear(Color.FromArgb(0, 0, 0, 0));
                ds.DrawImage(
                    bitmap,
                    new Rect(0, 0, sizeTarget.Width, sizeTarget.Height),
                    new Rect(0, 0, sizeSource.Width, sizeSource.Height),
                    1,
                    CanvasImageInterpolation.HighQualityCubic);
            }

            return(surface);
        }
示例#16
0
        private CompositionDrawingSurface SampleImageColor(CanvasBitmap bitmap, CompositionGraphicsDevice device, Size sizeTarget)
        {
            // Extract the color to tint the blur with
            Color predominantColor = ExtractPredominantColor(bitmap.GetPixelColors(), bitmap.Size);

            Size sizeSource = bitmap.Size;

            if (sizeTarget.IsEmpty)
            {
                sizeTarget = sizeSource;
            }

            // Create a heavily blurred version of the image
            GaussianBlurEffect blurEffect = new GaussianBlurEffect()
            {
                Source     = bitmap,
                BlurAmount = 20.0f
            };

            CompositionDrawingSurface surface = device.CreateDrawingSurface(sizeTarget,
                                                                            DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied);

            using (var ds = CanvasComposition.CreateDrawingSession(surface))
            {
                Rect destination = new Rect(0, 0, sizeTarget.Width, sizeTarget.Height);
                ds.FillRectangle(destination, predominantColor);
                ds.DrawImage(blurEffect, destination, new Rect(0, 0, sizeSource.Width, sizeSource.Height), .6f);
            }

            return(surface);
        }
示例#17
0
 private void FillSurfaceWithBitmap(CanvasBitmap canvasBitmap)
 {
     CanvasComposition.Resize(_surface, canvasBitmap.Size);
     using (var session = CanvasComposition.CreateDrawingSession(_surface))
     {
         session.Clear(Colors.Transparent);
         session.DrawImage(canvasBitmap);
     }
 }
示例#18
0
 void DrawSoftwareBitmap(SoftwareBitmap softwareBitmap, Size renderSize)
 {
     using (var drawingSession = CanvasComposition.CreateDrawingSession(_drawingSurface))
         using (var bitmap = CanvasBitmap.CreateFromSoftwareBitmap(drawingSession.Device, softwareBitmap))
         {
             drawingSession.DrawImage(bitmap,
                                      new Rect(0, 0, renderSize.Width, renderSize.Height));
         }
 }
示例#19
0
        public async Task Draw(CompositionGraphicsDevice device, Object drawingLock, CompositionDrawingSurface surface, Size size)
        {
            var canvasDevice = CanvasComposition.GetCanvasDevice(device);

            CanvasBitmap canvasBitmap;

            if (_softwareBitmap != null)
            {
                canvasBitmap = CanvasBitmap.CreateFromSoftwareBitmap(canvasDevice, _softwareBitmap);
            }
            else if (_file != null)
            {
                SoftwareBitmap softwareBitmap = await LoadFromFile(_file);

                canvasBitmap = CanvasBitmap.CreateFromSoftwareBitmap(canvasDevice, softwareBitmap);
            }
            else
            {
                canvasBitmap = await CanvasBitmap.LoadAsync(canvasDevice, _uri);
            }


            var bitmapSize = canvasBitmap.Size;

            //
            // Because the drawing is done asynchronously and multiple threads could
            // be trying to get access to the device/surface at the same time, we need
            // to do any device/surface work under a lock.
            //
            lock (drawingLock)
            {
                Size surfaceSize = size;
                if (surface.Size != size || surface.Size == new Size(0, 0))
                {
                    // Resize the surface to the size of the image
                    CanvasComposition.Resize(surface, bitmapSize);
                    surfaceSize = bitmapSize;
                }

                // Allow the app to process the bitmap if requested
                if (_handler != null)
                {
                    _handler(surface, canvasBitmap, device);
                }
                else
                {
                    // Draw the image to the surface
                    using (var session = CanvasComposition.CreateDrawingSession(surface))
                    {
                        session.Clear(Windows.UI.Color.FromArgb(0, 0, 0, 0));
                        session.DrawImage(canvasBitmap, new Rect(0, 0, surfaceSize.Width, surfaceSize.Height), new Rect(0, 0, bitmapSize.Width, bitmapSize.Height));
                    }
                }
            }
        }
示例#20
0
 void Draw()
 {
     using (CanvasDrawingSession ds = CanvasComposition.CreateDrawingSession(DrawingSurface))
     {
         var format = new CanvasTextFormat
         {
             FontSize = 60
         };
         ds.DrawText("F**k yeah baby", Vector2.Zero, Colors.DarkOrange, format);
     }
 }
        void LoadSurface(CompositionDrawingSurface surface, string path)
        {
            // Draw to surface.
            using (var ds = CanvasComposition.CreateDrawingSession(surface))
            {
                ds.Clear(Colors.Transparent);

                var rect = new Windows.Foundation.Rect(0, 0, _rectWidth, _rectHeight);
                ds.FillRectangle(rect, Colors.Coral);
            }
        }
示例#22
0
 public void RedrawSurface()
 {
     _imageLoader.DrawIntoSurface(_surface, (surface, device) =>
     {
         using (var session = CanvasComposition.CreateDrawingSession(surface))
         {
             session.Clear(Colors.Transparent);
             session.FillCircle(new Vector2(_radius, _radius), _radius, _color);
         }
     });
 }
示例#23
0
        static public CompositionDrawingSurface LoadText(string text, Size sizeTarget, CanvasTextFormat textFormat, Color textColor, Color bgColor)
        {
            CompositionDrawingSurface surface = _compositionDevice.CreateDrawingSurface(sizeTarget, DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied);

            using (var ds = CanvasComposition.CreateDrawingSession(surface))
            {
                ds.Clear(bgColor);
                ds.DrawText(text, new Rect(0, 0, sizeTarget.Width, sizeTarget.Height), textColor, textFormat);
            }

            return(surface);
        }
示例#24
0
        private static async Task <CompositionSurfaceBrush> LoadWin2DSurfaceBrushFromImageAsync(
            [NotNull] Compositor compositor, [NotNull] Uri uri, bool reload = false)
        {
            // Lock the semaphore and check the cache first
            await Win2DSemaphore.WaitAsync();

            if (!reload && SurfacesCache.TryGetValue(uri.ToString(), out CompositionSurfaceBrush cached))
            {
                Win2DSemaphore.Release();
                return(cached);
            }

            // Load the image
            CompositionSurfaceBrush brush;

            try
            {
                // This will throw and the canvas will re-initialize the Win2D device if needed
                CanvasDevice sharedDevice = CanvasDevice.GetSharedDevice();
                using (CanvasBitmap bitmap = await CanvasBitmap.LoadAsync(sharedDevice, uri))
                {
                    // Get the device and the target surface
                    CompositionGraphicsDevice device  = CanvasComposition.CreateCompositionGraphicsDevice(compositor, sharedDevice);
                    CompositionDrawingSurface surface = device.CreateDrawingSurface(default(Size),
                                                                                    DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied);

                    // Calculate the surface size
                    Size size = bitmap.Size;
                    CanvasComposition.Resize(surface, size);

                    // Draw the image on the surface and get the resulting brush
                    using (CanvasDrawingSession session = CanvasComposition.CreateDrawingSession(surface))
                    {
                        session.Clear(Color.FromArgb(0, 0, 0, 0));
                        session.DrawImage(bitmap, new Rect(0, 0, size.Width, size.Height), new Rect(0, 0, size.Width, size.Height));
                        brush = surface.Compositor.CreateSurfaceBrush(surface);
                    }
                }
            }
            catch
            {
                // Device error
                brush = null;
            }
            String key = uri.ToString();

            if (brush != null && !SurfacesCache.ContainsKey(key))
            {
                SurfacesCache.Add(key, brush);
            }
            Win2DSemaphore.Release();
            return(brush);
        }
        internal void ReDraw(Rect viewPort)
        {
            _visibleList.Clear();
            double top    = double.MaxValue,
                   bottom = double.MinValue,
                   left   = double.MaxValue,
                   right  = double.MinValue;

            foreach (var drawable in _drawableList)
            {
                if (drawable.IsVisible(viewPort))
                {
                    _visibleList.Add(drawable);

                    bottom = Math.Max(drawable.Bounds.Bottom, bottom);
                    right  = Math.Max(drawable.Bounds.Right, right);
                    top    = Math.Min(drawable.Bounds.Top, top);
                    left   = Math.Min(drawable.Bounds.Left, left);
                }
            }

            Rect toDraw;

            if (_visibleList.Any())
            {
                toDraw = new Rect(Math.Max(left, 0), Math.Max(top, 0), Math.Max(right - left, 0), Math.Max(bottom - top, 0));

                toDraw.Union(viewPort);
            }
            else
            {
                toDraw = viewPort;
            }

            if (toDraw.Height > Height)
            {
                toDraw.Height = Height;
            }

            if (toDraw.Width > Width)
            {
                toDraw.Width = Width;
            }

            using (CanvasDrawingSession drawingSession = CanvasComposition.CreateDrawingSession(_drawingSurface, toDraw))
            {
                drawingSession.Clear(Colors.White);
                foreach (var drawable in _visibleList)
                {
                    drawable.Draw(drawingSession, toDraw);
                }
            }
        }
        internal void ReDraw(Rect viewPort)
        {
            var toDraw = GetDrawingBoundaries(viewPort);

            using (var drawingSession = CanvasComposition.CreateDrawingSession(_drawingSurface, toDraw))
            {
                drawingSession.Clear(Colors.White);
                foreach (var drawable in _visibleList)
                {
                    drawable.Draw(drawingSession, toDraw);
                }
            }
        }
示例#27
0
        public void ProcessFrame(Direct3D11CaptureFrame frame)
        {
            bool needsReset     = false;
            bool recreateDevice = false;

            if ((frame.ContentSize.Width != _lastSize.Width) ||
                (frame.ContentSize.Height != _lastSize.Height))
            {
                needsReset = true;
                _lastSize  = frame.ContentSize;
            }


            try
            {
                IsRunning = true;

                CanvasBitmap canvasBitmap = CanvasBitmap.CreateFromDirect3D11Surface(_canvasDevice, frame.Surface);
                //_currentFrame = canvasBitmap;
                TakeSegments(canvasBitmap);
                Blur();
                if (SendingAction.IsCompleted)
                {
                    SendingAction  = Task.Run(SendToA);
                    Frametime.Text = "Frametime: " + FrameRate();
                }
                //SendToA();
                if (ShowCapture.IsChecked == true)
                {
                    Task.Run(() => FillSurfaceWithBitmap(canvasBitmap));
                }
                else
                {
                    using (var session = CanvasComposition.CreateDrawingSession(_surface))
                    {
                        session.Clear(Colors.Transparent);
                    }
                }
            }
            catch (Exception e) when(_canvasDevice.IsDeviceLost(e.HResult))
            {
                needsReset     = true;
                recreateDevice = true;
            }

            if (needsReset)
            {
                ResetFramePool(frame.ContentSize, recreateDevice);
            }
        }
示例#28
0
        public void DrawTile(Rect rect, int tileRow, int tileColumn)
        {
            Color randomColor = Color.FromArgb((byte)255, (byte)randonGen.Next(255), (byte)randonGen.Next(255), (byte)randonGen.Next(255));

            using (CanvasDrawingSession drawingSession = CanvasComposition.CreateDrawingSession(drawingSurface, rect))
            {
                drawingSession.Clear(randomColor);
                CanvasTextFormat tf = new CanvasTextFormat()
                {
                    FontSize = 72
                };
                drawingSession.DrawText($"{tileColumn},{tileRow}", new Vector2(50, 50), Colors.Green, tf);
            }
        }
示例#29
0
        static public async Task <CompositionDrawingSurface> LoadFromUri(Uri uri)
        {
            CanvasBitmap CBitmap = await CanvasBitmap.LoadAsync(_canvasDevice, uri);

            CompositionDrawingSurface DrawingSurface = _compositionDevice.CreateDrawingSurface(CBitmap.Size, DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied);

            using (CanvasDrawingSession DraingSession = CanvasComposition.CreateDrawingSession(DrawingSurface))
            {
                DraingSession.Clear(Color.FromArgb(0, 0, 0, 0));
                DraingSession.DrawImage(CBitmap, new Rect(0, 0, CBitmap.Size.Width, CBitmap.Size.Height));
            }

            return(DrawingSurface);
        }
示例#30
0
        private void ApplyBlurEffect(CompositionDrawingSurface surface, CanvasBitmap bitmap, CompositionGraphicsDevice device)
        {
            GaussianBlurEffect blurEffect = new GaussianBlurEffect()
            {
                Source     = bitmap,
                BlurAmount = 40.0f,
                BorderMode = EffectBorderMode.Hard,
            };

            using (var ds = CanvasComposition.CreateDrawingSession(surface))
            {
                ds.DrawImage(blurEffect);
                ds.FillRectangle(new Rect(0, 0, surface.Size.Width, surface.Size.Height), Windows.UI.Color.FromArgb(60, 0, 0, 0));
            }
        }