/// <summary> /// Resizes the SurfaceImage with the given size and redraws the SurfaceImage by loading /// image from the new Uri. /// </summary> /// <param name="uri">Uri of the image to be loaded onto the SurfaceImage.</param> /// <param name="size">New size of the SurfaceImage</param> /// <param name="options">Describes the image's resize and alignment options in the allocated space.</param> /// <returns>Task</returns> public async Task RedrawAsync(Uri uri, Size size, CompositionSurfaceImageOptions options) { // If the given Uri differs from the previously stored Uri // dispose the existing canvasBitmap if (!_uri.IsEqualTo(uri)) { _canvasBitmap?.Dispose(); _canvasBitmap = null; } // Set the image options Options = options; // Resize the surface only if AutoResize option is disabled if (!Options.AutoResize) { // resize the SurfaceImage _generator.ResizeDrawingSurface(_surfaceLock, _surface, size); // Set the size Size = _surface?.Size ?? new Size(0, 0); } // Set the new Uri of the image to be loaded _uri = uri; // Reload the SurfaceImage await RedrawSurfaceImageInternalAsync(); }
/// <summary> /// Resizes the MaskSurface with the given size and redraws the MaskSurface /// with the new geometry and fills it either with White color /// (if the MaskMode is True) or with the foreground brush /// (if the MaskMode is False). /// </summary> /// <param name="size">New size of the mask</param> /// <param name="geometry">New CanvasGeometry to be applied to the mask</param> public void Redraw(Size size, CanvasGeometry geometry) { // Resize the mask surface _generator.ResizeDrawingSurface(_surfaceLock, _surface, size); // Set the size Size = _surface?.Size ?? new Size(0, 0); // Set the new geometry _geometry = geometry; // Redraw the mask surface RedrawSurfaceInternal(); }
/// <summary> /// Resizes and redraws the IImageMaskSurface using the given CanvasBitmap's alpha values with the given padding /// using the given options. /// </summary> /// <param name="surfaceBitmap">Image whose alpha values are to be used to create the mask.</param> /// <param name="size">New size of the IImageMaskSurface.</param> /// <param name="padding">The padding between the IImageMaskSurface outer bounds and the bounds of the area where /// the mask, created from the loaded image's alpha values, should be rendered.</param> /// <param name="options">The image's resize, alignment and blur radius options in the allocated space.</param> public void Redraw(CanvasBitmap surfaceBitmap, Size size, Thickness padding, ImageSurfaceOptions options) { if (_canvasBitmap != surfaceBitmap) { // Dispose the previous canvas bitmap resource (if any) if (_canvasBitmap != null) { _canvasBitmap.Dispose(); _canvasBitmap = null; } if (surfaceBitmap != null) { // No need to copy again if _canvasBitmap and surfaceBitmap are same if (_canvasBitmap != surfaceBitmap) { // Copy the surface bitmap onto _canvasBitmap _canvasBitmap = CanvasBitmap.CreateFromBytes(_generator.Device, surfaceBitmap.GetPixelBytes(), (int)surfaceBitmap.Bounds.Width, (int)surfaceBitmap.Bounds.Height, surfaceBitmap.Format); } } else { _canvasBitmap = null; } } _uri = null; _raiseLoadCompletedEvent = false; // Set the options Options = options; // Resize if required if (Size != size) { // resize the IImageMaskSurface _generator.ResizeDrawingSurface(_surfaceLock, _surface, size); // Set the size Size = _surface?.Size ?? new Size(0, 0); } // Set the mask padding MaskPadding = padding; // Redraw the IImageMaskSurface RedrawSurface(); }
/// <summary> /// Resizes the GaussianMaskSurface with the given size and redraws the GaussianMaskSurface /// with the new geometry and fills it with White color. A Gaussian blur is applied to the /// new geometry. /// </summary> /// <param name="size">New size of the mask</param> /// <param name="geometry">New CanvasGeometry to be applied to the mask</param> /// <param name="offset">The offset from the top left corner of the ICompositionSurface where /// the Geometry is rendered.</param> /// <param name="blurRadius">Radius of Gaussian Blur to be applied on the GaussianMaskSurface</param> public void Redraw(Size size, CanvasGeometry geometry, Vector2 offset, float blurRadius) { // Resize the mask surface _generator.ResizeDrawingSurface(_surfaceLock, _surface, size); // Set the size Size = _surface?.Size ?? new Size(0, 0); // Set the offset Offset = offset; // Set the new geometry Geometry = geometry; // Set the new blur radius BlurRadius = blurRadius; // Redraw the mask surface RedrawSurface(); }
/// <summary> /// Resizes the IMaskSurface with the given size and redraws the IMaskSurface /// with the new geometry and fills it with White color /// </summary> /// <param name="size">New size of the mask</param> /// <param name="geometry">New CanvasGeometry to be applied to the IMaskSurface</param> /// <param name="offset">The offset from the top left corner of the ICompositionSurface where /// the Geometry is rendered.</param> public void Redraw(Size size, CanvasGeometry geometry, Vector2 offset) { if (Size != size) { // Resize the mask surface _generator.ResizeDrawingSurface(_surfaceLock, _surface, size); // Set the size Size = _surface?.Size ?? new Size(0, 0); } // Set the new geometry Geometry = geometry; // Set the offset Offset = offset; // Redraw the mask surface RedrawSurface(); }
/// <summary> /// Resizes and redraws the IImageSurface using the given CanvasBitmap using the given options. /// </summary> /// <param name="surfaceBitmap">Image whose alpha values are to be used to create the mask.</param> /// <param name="size">New size of the IImageSurface.</param> /// <param name="options">The image's resize, alignment options in the allocated space.</param> public void Redraw(CanvasBitmap surfaceBitmap, Size size, ImageSurfaceOptions options) { if (_canvasBitmap != surfaceBitmap) { // Dispose the previous canvas bitmap resource (if any) if (_canvasBitmap != null) { _canvasBitmap.Dispose(); _canvasBitmap = null; } if (surfaceBitmap != null) { if (_canvasBitmap != surfaceBitmap) { // Copy the surface bitmap onto _canvasBitmap _canvasBitmap = CanvasBitmap.CreateFromBytes(_generator.Device, surfaceBitmap.GetPixelBytes(), (int)surfaceBitmap.Bounds.Width, (int)surfaceBitmap.Bounds.Height, surfaceBitmap.Format); } } else { _canvasBitmap = null; } } _uri = null; _raiseLoadCompletedEvent = false; // Set the options Options = options; // Resize the surface only if AutoResize option is disabled if (!Options.AutoResize && Size != size) { // resize the IImageMaskSurface _generator.ResizeDrawingSurface(_surfaceLock, _surface, size); // Set the size Size = _surface?.Size ?? new Size(0, 0); } // Redraw the IImageMaskSurface RedrawSurface(); }