当前位置: 首页>>代码示例>>C#>>正文


C# CGContext.DrawRadialGradient方法代码示例

本文整理汇总了C#中CGContext.DrawRadialGradient方法的典型用法代码示例。如果您正苦于以下问题:C# CGContext.DrawRadialGradient方法的具体用法?C# CGContext.DrawRadialGradient怎么用?C# CGContext.DrawRadialGradient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CGContext的用法示例。


在下文中一共展示了CGContext.DrawRadialGradient方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawInContext

        public override void DrawInContext(CGContext ctx)
        {
            base.DrawInContext(ctx);
            var colorSpace = CGColorSpace.CreateDeviceRGB();

            if (colorSpace == null)
            {
                throw new InvalidOperationException();
            }

            var gradient = new CGGradient(colorSpace,
                new nfloat[] { 1f, 1f, 1f, 1f, 0.86f, 0.86f, 0.86f, 1f },
                               new nfloat[] { 0.2f, 0.95f });
            var center = new CGPoint(this.Bounds.Width / 2, this.Bounds.Height / 2);
            var radius = new nfloat(Math.Min(this.Bounds.Width, this.Bounds.Height));

            ctx.DrawRadialGradient(gradient, center, 0, center, radius, CGGradientDrawingOptions.DrawsAfterEndLocation);
        }
开发者ID:ably,项目名称:demo-mobile-xamarin,代码行数:18,代码来源:RadialGradient.cs

示例2: DrawInContext

    public override void DrawInContext(CGContext context)
    {
        // The clipping rects we plan to use, which also defines the location and span of each gradient
        var clips = new RectangleF []
        {
            new RectangleF(10, 30, 60, 90),
            new RectangleF(90, 30, 60, 90),
            new RectangleF(170, 30, 60, 90),
            new RectangleF(250, 30, 60, 90),
            new RectangleF(30, 140, 120, 120),
            new RectangleF(170, 140, 120, 120),
            new RectangleF(30, 280, 120, 120),
            new RectangleF(170, 280, 120, 120),
        };

        // Linear Gradients
        PointF start, end;

        // Clip to area to draw the gradient, and draw it. Since we are clipping, we save the graphics state
        // so that we can revert to the previous larger area.
        context.SaveState();
        context.ClipToRect(clips[0]);

        // A linear gradient requires only a starting & ending point.
        // The colors of the gradient are linearly interpolated along the line segment connecting these two points
        // A gradient location of 0 means that color is expressed fully at the 'start' point
        // a location of 1 means that color is expressed fully at the 'end' point.
        // The gradient fills outwards perpendicular to the line segment connectiong start & end points
        // (which is why we need to clip the context, or the gradient would fill beyond where we want it to).
        // The gradient options (last) parameter determines what how to fill the clip area that is "before" and "after"
        // the line segment connecting start & end.
        start = demoLGStart(clips[0]);
        end = demoLGEnd(clips[0]);
        context.DrawLinearGradient(gradient, start, end, 0);
        context.RestoreState();

        // Same as above for each combination of CGGradientDrawingOptions.DrawsBeforeStartLocation & CGGradientDrawingOptions.DrawsAfterEndLocation

        context.SaveState();
        context.ClipToRect(clips[1]);
        start = demoLGStart(clips[1]);
        end = demoLGEnd(clips[1]);
        context.DrawLinearGradient(gradient, start, end, CGGradientDrawingOptions.DrawsBeforeStartLocation);
        context.RestoreState();

        context.SaveState();
        context.ClipToRect(clips[2]);
        start = demoLGStart(clips[2]);
        end = demoLGEnd(clips[2]);
        context.DrawLinearGradient(gradient, start, end, CGGradientDrawingOptions.DrawsAfterEndLocation);
        context.RestoreState();

        context.SaveState();
        context.ClipToRect(clips[3]);
        start = demoLGStart(clips[3]);
        end = demoLGEnd(clips[3]);
        context.DrawLinearGradient(gradient, start, end, CGGradientDrawingOptions.DrawsBeforeStartLocation | CGGradientDrawingOptions.DrawsAfterEndLocation);
        context.RestoreState();

        // Radial Gradients

        float startRadius, endRadius;

        // Clip to area to draw the gradient, and draw it. Since we are clipping, we save the graphics state
        // so that we can revert to the previous larger area.
        context.SaveState();
        context.ClipToRect(clips[4]);

        // A radial gradient requires a start & end point as well as a start & end radius.
        // Logically a radial gradient is created by linearly interpolating the center, radius and color of each
        // circle using the start and end point for the center, start and end radius for the radius, and the color ramp
        // inherant to the gradient to create a set of stroked circles that fill the area completely.
        // The gradient options specify if this interpolation continues past the start or end points as it does with
        // linear gradients.
        start = end = demoRGCenter(clips[4]);
        startRadius = demoRGInnerRadius(clips[4]);
        endRadius = demoRGOuterRadius(clips[4]);
        context.DrawRadialGradient(gradient, start, startRadius, end, endRadius, 0);
        context.RestoreState();

        // Same as above for each combination of CGGradientDrawingOptions.DrawsBeforeStartLocation & CGGradientDrawingOptions.DrawsAfterEndLocation

        context.SaveState();
        context.ClipToRect(clips[5]);
        start = end = demoRGCenter(clips[5]);
        startRadius = demoRGInnerRadius(clips[5]);
        endRadius = demoRGOuterRadius(clips[5]);
        context.DrawRadialGradient(gradient, start, startRadius, end, endRadius, CGGradientDrawingOptions.DrawsBeforeStartLocation);
        context.RestoreState();

        context.SaveState();
        context.ClipToRect(clips[6]);
        start = end = demoRGCenter(clips[6]);
        startRadius = demoRGInnerRadius(clips[6]);
        endRadius = demoRGOuterRadius(clips[6]);
        context.DrawRadialGradient(gradient, start, startRadius, end, endRadius, CGGradientDrawingOptions.DrawsAfterEndLocation);
        context.RestoreState();

        context.SaveState();
        context.ClipToRect(clips[7]);
//.........这里部分代码省略.........
开发者ID:CVertex,项目名称:monotouch-samples,代码行数:101,代码来源:rendereddrawing.cs


注:本文中的CGContext.DrawRadialGradient方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。