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


C# CGContext.ClipToRect方法代码示例

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


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

示例1: DrawInContext

	public override void DrawInContext (CGContext context)
	{
		var imageRect = new RectangleF (8, 8, 64, 64);
		
		// Note: The images are actually drawn upside down because Quartz image drawing expects
		// the coordinate system to have the origin in the lower-left corner, but a UIView
		// puts the origin in the upper-left corner. For the sake of brevity (and because
		// it likely would go unnoticed for the image used) this is not addressed here.
		// For the demonstration of PDF drawing however, it is addressed, as it would definately
		// be noticed, and one method of addressing it is shown there.
	
		// Draw the image in the upper left corner (0,0) with size 64x64
		context.DrawImage (imageRect, image);
		
		// Tile the same image across the bottom of the view
		// CGContextDrawTiledImage() will fill the entire clipping area with the image, so to avoid
		// filling the entire view, we'll clip the view to the rect below. This rect extends
		// past the region of the view, but since the view's rectangle has already been applied as a clip
		// to our drawing area, it will be intersected with this rect to form the final clipping area
		context.ClipToRect(new RectangleF (0, 80, Bounds.Width, Bounds.Height));
		
		// The origin of the image rect works similarly to the phase parameter for SetLineDash and
		// SetPatternPhase and specifies where in the coordinate system the "first" image is drawn.
		// The size (previously set to 64x64) specifies the size the image is scaled to before being tiled.
		imageRect.X = 32;
		imageRect.Y = 112;
		context.DrawTiledImage (imageRect, image);
		
		// Highlight the "first" image from the DrawTiledImage call.
		context.SetRGBFillColor (1, 0, 0, 0.5f);
		context.FillRect (imageRect);
		
		// And stroke the clipped area
		context.SetLineWidth (3);
		context.SetRGBStrokeColor (1, 0, 0, 1);
		context.StrokeRect (context.GetClipBoundingBox ());
	}
开发者ID:BoogieMAN2K,项目名称:monotouch-samples,代码行数:37,代码来源:ImageDrawing.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.ClipToRect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。