コード例 #1
0
        /// <inheritdoc/>
        protected override bool OnDraw(CanvasDevice device, CanvasDrawingSession session, Vector2 size)
        {
            // Create our Brush
            if (GradientStops != null && GradientStops.Count > 0)
            {
                var gradientBrush = new CanvasRadialGradientBrush(
                    device,
                    GradientStops.ToWin2DGradientStops(),
                    SpreadMethod.ToEdgeBehavior(),
                    (CanvasAlphaMode)(int)AlphaMode,
                    ColorInterpolationMode.ToCanvasColorSpace(),
                    CanvasColorSpace.Srgb,
                    CanvasBufferPrecision.Precision8UIntNormalized)
                {
                    // Calculate Surface coordinates from 0.0-1.0 range given in WPF brush
                    RadiusX = size.X * (float)RadiusX,
                    RadiusY = size.Y * (float)RadiusY,
                    Center  = size * Center.ToVector2(),

                    // Calculate Win2D Offset from origin/center used in WPF brush
                    OriginOffset = size * (GradientOrigin.ToVector2() - Center.ToVector2()),
                };

                // Use brush to draw on our canvas
                session.FillRectangle(size.ToRect(), gradientBrush);

                gradientBrush.Dispose();

                return(true);
            }

            return(false);
        }
コード例 #2
0
 private void Dispose(bool disposing)
 {
     if (_canvasRadialGradientBrush != null)
     {
         _canvasRadialGradientBrush.Dispose();
         _canvasRadialGradientBrush = null;
     }
 }
コード例 #3
0
 private void Dispose(bool disposing)
 {
     if (_canvasRadialGradientBrush != null)
     {
         try
         {
             _canvasRadialGradientBrush.Dispose();
         }
         catch
         {
             // Ignore
         }
         finally
         {
             _canvasRadialGradientBrush = null;
         }
     }
 }