/// <summary> /// Creates the CompositionMask having the given size, geometry & brush /// </summary> /// <param name="size">Size of the mask</param> /// <param name="geometry">Geometry of the mask</param> /// <param name="brush">Brush to fill the geometry.</param> /// <returns>ICompositionMask</returns> public ICompositionMask CreateMask(Size size, CanvasGeometry geometry, ICanvasBrush brush) { // Initialize the mask ICompositionMask mask = new CompositionMask(this, size, geometry, brush); // Render the mask mask.Redraw(); return(mask); }
/// <summary> /// Creates a CompositionMask having the given size and geometry /// </summary> /// <param name="size">Size of the mask</param> /// <param name="geometry">Geometry of the mask</param> /// <returns></returns> public Task <ICompositionMask> CreateMaskAsync(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) { ICompositionMask mask = new CompositionMask(this, size, geometry); // Render the mask to the surface using (var session = CanvasComposition.CreateDrawingSession((CompositionDrawingSurface)mask.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); } } return mask; } })); }