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


C# CGContext.SaveState方法代码示例

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


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

示例1: FillRect

 public static void FillRect(CGContext context, RectangleF rect, CGColor color)
 {
     context.SaveState();
     context.AddRect(rect);
     context.Clip();
     context.SetFillColor(color);
     context.FillRect(rect);
     context.RestoreState();
 }
开发者ID:pascalfr,项目名称:MPfm,代码行数:9,代码来源:CoreGraphicsHelper.cs

示例2: DrawEllipsis

 public static void DrawEllipsis(CGContext context, RectangleF rect, CGColor color, float lineWidth)
 {
     context.SaveState();
     context.SetStrokeColor(color);
     context.SetLineWidth(lineWidth);
     context.AddEllipseInRect(rect);
     context.StrokePath();
     context.RestoreState();
 }
开发者ID:pascalfr,项目名称:MPfm,代码行数:9,代码来源:CoreGraphicsHelper.cs

示例3: DrawStars

        protected void DrawStars(CGContext context)
        {
            context.SetRGBFillColor (1f, 0f, 0f, 1f);

            // save state so that as we translate (move the origin around,
            // it goes back to normal when we restore)
            context.SetRGBFillColor (0f, 0f, 0.329f, 1.0f);
            context.SaveState ();
            context.TranslateCTM (30, 300);
            DrawStar (context, 30);
            context.RestoreState ();

            context.SetRGBFillColor (1f, 0f, 0f, 1f);
            context.SaveState ();
            context.TranslateCTM (120, 200);
            DrawStar (context, 30);
            context.RestoreState ();
        }
开发者ID:BoogieMAN2K,项目名称:monotouch-samples,代码行数:18,代码来源:CameraOverlayView.cs

示例4: DrawLayer

 public override void DrawLayer(CALayer layer, CGContext context)
 {
     context.SaveState ();
     context.SetFillColor (1.0f, 1.0f, 1.0f, 1.0f);
     context.FillRect (context.GetClipBoundingBox ());
     context.TranslateCTM (0.0f, layer.Bounds.Size.Height);
     context.ScaleCTM (1.0f, -1.0f);
     context.ConcatCTM (this.oParentController.currentPDFPage.GetDrawingTransform (CGPDFBox.Crop, layer.Bounds, 0, true));
     context.DrawPDFPage (this.oParentController.currentPDFPage);
     context.RestoreState ();
 }
开发者ID:Emasoft,项目名称:IpaziaPDFReader,代码行数:11,代码来源:TiledLayerDelegate.cs

示例5: DrawContentView

		public void DrawContentView(RectangleF rect, CGContext context, UITableViewElementCell cell)
		{
			context.SaveState();
			float r = 0;
			float g = 0;
			float b = 0;

			var gradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), new float[] { r, g, b, 0.20f, r, g, b, 0.40f }, new float[] { 0, 1 });			
			context.DrawLinearGradient(gradient, new PointF(rect.Left, rect.Top), new PointF(rect.Left, rect.Bottom), CGGradientDrawingOptions.DrawsBeforeStartLocation);

			context.RestoreState();
		}
开发者ID:anujb,项目名称:MonoMobile.MVVM,代码行数:12,代码来源:SmokeyTheme.cs

示例6: DrawLayer

        public void DrawLayer(CALayer layer, CGContext context)
        {
            // fill with white background
            context.SetFillColor (1f, 1f, 1f, 1f);
            context.FillRect (Bounds);
            context.SaveState ();

            // flip page so we render it as it's meant to be read
            context.TranslateCTM (0f, Bounds.Height);
            context.ScaleCTM (1f, -1f);

            // scale page at the view-zoom level
            context.ScaleCTM (MyScale, MyScale);
            context.DrawPDFPage (Page);
            context.RestoreState ();
        }
开发者ID:CBrauer,项目名称:monotouch-samples,代码行数:16,代码来源:TiledPdfView.cs

示例7: DrawContentView

		public void DrawContentView(RectangleF rect, CGContext context, UITableViewElementCell cell)
		{
			context.SaveState();
			
			var backgroundColor = CellBackgroundColor;
			if (backgroundColor != null)
			{
				if (backgroundColor == UIColor.Clear)
					backgroundColor = UIColor.White;
				
				context.SetFillColorWithColor(backgroundColor.ColorWithAlpha(0.4f).CGColor);
				context.SetBlendMode(CGBlendMode.Overlay);
				context.FillRect(rect);
			}
			
			context.RestoreState();
		}
开发者ID:CartBlanche,项目名称:MonoMobile.MVVM,代码行数:17,代码来源:SampleTheme.cs

示例8: MeasureStringWidth

        // TODO: Cannot use NSAttributedString in iOS5, only iOS6+
//        public static RectangleF MeasureString(SizeF sizeConstraint, string text, string fontName, float fontSize)
//        {
//            NSMutableDictionary dict = new NSMutableDictionary();
//            dict.Add(NSAttributedString.FontAttributeName, NSFont.FromFontName(fontName, fontSize));
//            NSString nsstr = new NSString(text);
//            RectangleF rect = nsstr.BoundingRectWithSize(sizeConstraint, NSStringDrawingOptions.UsesFontLeading | NSStringDrawingOptions.UsesLineFragmentOrigin, dict);
//            return rect;
//        }
        
        public static float MeasureStringWidth(CGContext context, string text, string fontName, float fontSize)
        {
			if (string.IsNullOrEmpty(text))
				return 0;

            context.SaveState();
            PointF pos = context.TextPosition;
            context.SelectFont(fontName, fontSize, CGTextEncoding.MacRoman);
            context.TextMatrix = CGAffineTransform.MakeScale(1.0f, -1.0f);
            //context.TranslateCTM(0, 20);
            context.ScaleCTM(1, -1);
            context.SetTextDrawingMode(CGTextDrawingMode.Invisible);
            context.ShowTextAtPoint(pos.X, pos.Y, text);
            PointF pos2 = context.TextPosition;
            context.RestoreState();
            
            return pos2.X - pos.X;
        }
开发者ID:pascalfr,项目名称:MPfm,代码行数:28,代码来源:CoreGraphicsHelper.cs

示例9: DrawLayer

		public override void DrawLayer (CALayer layer, CGContext context)
		{
			// keep a copy since (a) it's a _virtual_ property and (b) it could change between filling and flipping
			RectangleF bounds = view.Bounds;
			
			// fill with white background
			context.SetFillColor (1.0f, 1.0f, 1.0f, 1.0f);
			context.FillRect (bounds);
			context.SaveState ();

			// flip page so we render it as it's meant to be read
			context.TranslateCTM (0.0f, bounds.Height);
			context.ScaleCTM (1.0f, -1.0f);
	
			// scale page at the view-zoom level
			context.ScaleCTM (view.Scale, view.Scale);
			context.DrawPDFPage (view.Page);
			context.RestoreState ();
		}
开发者ID:rojepp,项目名称:monotouch-samples,代码行数:19,代码来源:TiledPdfView.cs

示例10: DrawInContext

	public override void DrawInContext (CGContext context)
	{
		// Drawing with a white stroke color
		context.SetRGBStrokeColor (1, 1, 1, 1);
		// And drawing with a blue fill color
		context.SetRGBFillColor (0, 0, 1, 1);
		// Draw them with a 2 stroke width so they are a bit more visible.
		context.SetLineWidth (2);
		
		// Add Rect to the current path, then stroke it
		context.AddRect (new RectangleF (30, 30, 60, 60));
		context.StrokePath ();
		
		// Stroke Rect convenience that is equivalent to above
		context.StrokeRect (new RectangleF (30, 120, 60, 60));
		
		// Stroke rect convenience equivalent to the above, plus a call to context.SetLineWidth ().
		context.StrokeRectWithWidth (new RectangleF (30, 210, 60, 60), 10);
		// Demonstate the stroke is on both sides of the path.
		context.SaveState ();
		context.SetRGBStrokeColor (1, 0, 0, 1);
		context.StrokeRectWithWidth (new RectangleF (30, 210, 60, 60), 2);
		context.RestoreState ();
		
		var rects = new RectangleF []
		{
			new RectangleF (120, 30, 60, 60),
			new RectangleF (120, 120, 60, 60),
			new RectangleF (120, 210, 60, 60),
		};
		// Bulk call to add rects to the current path.
		context.AddRects (rects);
		context.StrokePath ();
		
		// Create filled rectangles via two different paths.
		// Add/Fill path
		context.AddRect (new RectangleF (210, 30, 60, 60));
		context.FillPath ();
		// Fill convienience.
		context.FillRect (new RectangleF (210, 120, 60, 60));
	}	
开发者ID:BoogieMAN2K,项目名称:monotouch-samples,代码行数:41,代码来源:PolyDrawing.cs

示例11: DrawInContext

	public override void DrawInContext (CGContext context)
	{
		// PDF page drawing expects a Lower-Left coordinate system, so we flip the coordinate system
		// before we start drawing.
		context.TranslateCTM (0, Bounds.Height);
		context.ScaleCTM (1, -1);
		
		// Grab the first PDF page
		using (CGPDFPage page = doc.GetPage (1)){
			// We're about to modify the context CTM to draw the PDF page where we want it, so save the graphics state in case we want to do more drawing
			context.SaveState ();
			
			// CGPDFPageGetDrawingTransform provides an easy way to get the transform for a PDF page. It will scale down to fit, including any
			// base rotations necessary to display the PDF page correctly.
			
			CGAffineTransform pdfTransform = page.GetDrawingTransform (CGPDFBox.Crop, Bounds, 0, true);

			// And apply the transform.
			context.ConcatCTM (pdfTransform);
			// Finally, we draw the page and restore the graphics state for further manipulations!
			context.DrawPDFPage (page);
			context.RestoreState();
		}
	}	
开发者ID:BoogieMAN2K,项目名称:monotouch-samples,代码行数:24,代码来源:ImageDrawing.cs

示例12: DrawInContext

	public override void DrawInContext (CGContext context)
	{
		// Drawing lines with a white stroke color
		context.SetRGBStrokeColor(1, 1, 1, 1);
		
		// Preserve the current drawing state
		context.SaveState();
		
		// Set the line width so that the cap is visible
		context.SetLineWidth(20);
		
		// Line caps demonstration
		
		// Line cap butt, default.
		context.SetLineCap(CGLineCap.Butt);
		context.MoveTo(40, 30);
		context.AddLineToPoint(280, 30);
		context.StrokePath();
		
		// Line cap round
		context.SetLineCap(CGLineCap.Round);
		context.MoveTo(40, 65);
		context.AddLineToPoint(280, 65);
		context.StrokePath();
		
		// Line cap square
		context.SetLineCap(CGLineCap.Square);
		context.MoveTo(40, 100);
		context.AddLineToPoint(280, 100);
		context.StrokePath();
		
		// Restore the previous drawing state, and save it again.
		context.RestoreState();
		context.SaveState();
		
		// Set the line width so that the join is visible
		context.SetLineWidth(20);
		
		// Line join miter, default
		context.SetLineJoin(CGLineJoin.Miter);
		context.MoveTo(40, 260);
		context.AddLineToPoint(160, 140);
		context.AddLineToPoint(280, 260);
		context.StrokePath();
		
		// Line join round
		context.SetLineJoin(CGLineJoin.Round);
		context.MoveTo(40, 320);
		context.AddLineToPoint(160, 200);
		context.AddLineToPoint(280, 320);
		context.StrokePath();
		
		// Line join bevel
		context.SetLineJoin(CGLineJoin.Bevel);
		context.MoveTo(40, 380);
		context.AddLineToPoint(160, 260);
		context.AddLineToPoint(280, 380);
		context.StrokePath();
	
		// Restore the previous drawing state.
		context.RestoreState();
	
		// Demonstrate where the path that generated each line is
		context.SetRGBStrokeColor(1, 0, 0, 1);
		context.SetLineWidth(3);
		context.MoveTo(40, 30);
		context.AddLineToPoint(280, 30);
		context.MoveTo(40, 65);
		context.AddLineToPoint(280, 65);
		context.MoveTo(40, 100);
		context.AddLineToPoint(280, 100);
		context.MoveTo(40, 260);
		context.AddLineToPoint(160, 140);
		context.AddLineToPoint(280, 260);
		context.MoveTo(40, 320);
		context.AddLineToPoint(160, 200);
		context.AddLineToPoint(280, 320);
		context.MoveTo(40, 380);
		context.AddLineToPoint(160, 260);
		context.AddLineToPoint(280, 380);
		context.StrokePath();
	}	
开发者ID:GSerjo,项目名称:monotouch-samples,代码行数:82,代码来源:LineDrawing.cs

示例13: DrawBorder

        private void DrawBorder(CGContext context, RectangleF rect)
        {
            context.SaveState ();

            context.BeginPath ();
            float lineSize = 2f;
            if (this.scaleFactor > 1) {
                lineSize += this.scaleFactor * .25f;
            }
            context.SetLineWidth (lineSize);
            context.SetStrokeColor (this.borderColor.CGColor);
            MakePath (context, rect);
            context.ClosePath ();
            context.StrokePath ();

            context.RestoreState ();
        }
开发者ID:Alxandr,项目名称:CustomBadge,代码行数:17,代码来源:CustomBadgeView.cs

示例14: DrawHandle

        private void DrawHandle(CGContext ctx)
        {
            ctx.SaveState();
            CGPoint handleCenter = pointOnCircleAtAngleFromNorth(_angleFromNorth);

            // Ensure that handle is drawn in the correct color
            //[self.handleColor set];
            HandleColor.SetColor();

            switch (_handleType)
            {
                case CircularSliderHandleType.CircularSliderHandleTypeSemiTransparentWhiteCircle:
                case CircularSliderHandleType.CircularSliderHandleTypeSemiTransparentBlackCircle:
                case CircularSliderHandleType.CircularSliderHandleTypeBigCircle:
                    {
                        Utils.drawFilledCircleInContext(ctx,
                                                 center: handleCenter,
                        radius: 0.5f * HandleWidth);
                        break;
                    }
                case CircularSliderHandleType.CircularSliderHandleTypeDoubleCircleWithClosedCenter:
                case CircularSliderHandleType.CircularSliderHandleTypeDoubleCircleWithOpenCenter:
                    {
                        DrawUnfilledLineBehindDoubleCircleHandle(ctx);

                        // Draw unfilled outer circle
                        Utils.drawUnfilledCircleInContext(ctx,
                            center: new CGPoint(handleCenter.X, handleCenter.Y),
                            radius: radiusForDoubleCircleOuterCircle(),
                            lineWidth: lineWidthForDoubleCircleOuterCircle());

                        if (_handleType == CircularSliderHandleType.CircularSliderHandleTypeDoubleCircleWithClosedCenter)
                        {
                            // Draw filled inner circle
                            Utils.drawFilledCircleInContext(ctx, center: handleCenter,
                                                               radius: Utils.outerRadiuOfUnfilledArcWithRadius(radiusForDoubleCircleInnerCircle(),
                                                                                                              lineWidthForDoubleCircleInnerCircle()));
                        }
                        else if (_handleType == CircularSliderHandleType.CircularSliderHandleTypeDoubleCircleWithOpenCenter)
                        {
                            // Draw unfilled inner circle
                            Utils.drawUnfilledCircleInContext(ctx,
                                                            center: new CGPoint(handleCenter.X, handleCenter.Y),
                                                            radius: radiusForDoubleCircleInnerCircle(),
                                                            lineWidth: lineWidthForDoubleCircleInnerCircle());
                        }

                        break;
                    }
            }

            ctx.RestoreState();
        }
开发者ID:xabre,项目名称:Xamarin-CircularSlider-SeekArc,代码行数:53,代码来源:CircularSlider.cs

示例15: FillGradient

 public static void FillGradient(CGContext context, RectangleF rect, CGColor color1, CGColor color2)
 {
     CGGradient gradientBackground;
     CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();
     
     float[] locationListBackground = new float[] { 1.0f, 0.0f };
     List<float> colorListBackground = new List<float>();
     colorListBackground.AddRange(color1.Components);
     colorListBackground.AddRange(color2.Components);
     gradientBackground = new CGGradient(colorSpace, colorListBackground.ToArray(), locationListBackground);
     
     context.SaveState();
     context.AddRect(rect);
     context.Clip();
     //context.ScaleCTM(1, -1);
     context.DrawLinearGradient(gradientBackground, new PointF(rect.X, rect.Y), new PointF(rect.X + rect.Width, rect.Y + rect.Height), CGGradientDrawingOptions.DrawsBeforeStartLocation);
     context.RestoreState();
 }       
开发者ID:pascalfr,项目名称:MPfm,代码行数:18,代码来源:CoreGraphicsHelper.cs


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