コード例 #1
0
        public GdiRadialGradientBrush(
            PointF center,
            float xRadius,
            float yRadius,
            GradientStop[] gradientStops)
        {
            this.gradientStops = gradientStops;
            this.graphicsPath  = new GraphicsPath();
            RectangleF rect = new RectangleF(new PointF(center.X - xRadius, center.Y - yRadius), new SizeF(xRadius * 2f, yRadius * 2f));

            if (!rect.IsEmpty)
            {
                this.graphicsPath.AddEllipse(rect);
                this.brush = (Brush) new PathGradientBrush(this.graphicsPath)
                {
                    CenterPoint         = center,
                    CenterColor         = gradientStops[0].Color,
                    InterpolationColors = GdiUtility.GetColorBlend(gradientStops)
                };
            }
            else
            {
                this.brush = (Brush) new SolidBrush(Color.Transparent);
            }
        }
コード例 #2
0
 public void SetGradientStops(GradientStop[] gradientStops)
 {
     if (gradientStops == null || gradientStops.Length == 0)
     {
         throw new ArgumentException(nameof(gradientStops));
     }
     this.gradientStops = gradientStops;
     this.rawBrush.InterpolationColors = GdiUtility.GetColorBlend(gradientStops);
 }
コード例 #3
0
 public GdiLinearGradientBrush(RectangleF rectangle, GradientStop[] gradientStops, float angle)
 {
     this.angle                        = angle;
     this.mode                         = RadLinearGradientMode.None;
     this.gradientStops                = gradientStops;
     rectangle.Width                   = Math.Max(1f, rectangle.Width);
     rectangle.Height                  = Math.Max(1f, rectangle.Height);
     this.rawBrush                     = new LinearGradientBrush(rectangle, Color.Black, Color.Black, angle);
     this.rawBrush.WrapMode            = WrapMode.TileFlipXY;
     this.rawBrush.InterpolationColors = GdiUtility.GetColorBlend(gradientStops);
 }
コード例 #4
0
        public void SetGradientStops(GradientStop[] gradientStops)
        {
            if (gradientStops == null || gradientStops.Length == 0)
            {
                throw new ArgumentException(nameof(gradientStops));
            }
            this.gradientStops = gradientStops;
            PathGradientBrush brush = this.brush as PathGradientBrush;

            if (brush == null)
            {
                return;
            }
            brush.CenterColor         = gradientStops[0].Color;
            brush.InterpolationColors = GdiUtility.GetColorBlend(gradientStops);
        }
コード例 #5
0
        public GdiLinearGradientBrush(
            RectangleF rectangle,
            GradientStop[] gradientStops,
            RadLinearGradientMode mode)
        {
            if (mode == RadLinearGradientMode.None)
            {
                throw new NotSupportedException("The brush cannot be initialized with " + (object)mode);
            }
            this.mode          = mode;
            this.angle         = 0.0f;
            this.gradientStops = gradientStops;
            rectangle.Width    = Math.Max(1f, rectangle.Width);
            rectangle.Height   = Math.Max(1f, rectangle.Height);
            this.rawBrush      = new LinearGradientBrush(rectangle, Color.Black, Color.Black, (LinearGradientMode)this.mode);
            LinearGradientBrush rawBrush = this.rawBrush;

            GradientStop[] gradientStops1;
            if (gradientStops.Length == 1)
            {
                gradientStops1 = new GradientStop[2]
                {
                    new GradientStop(gradientStops[0].Color, 0.0f),
                    new GradientStop(gradientStops[0].Color, 1f)
                }
            }
            ;
            else
            {
                gradientStops1 = gradientStops;
            }
            ColorBlend colorBlend = GdiUtility.GetColorBlend(gradientStops1);

            rawBrush.InterpolationColors = colorBlend;
            this.rawBrush.WrapMode       = WrapMode.TileFlipXY;
        }