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


C# CGContext.TranslateCTM方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: DrawStar

		/// <summary>
		/// Draws a star at the bottom left of the context of the specified diameter
		/// </summary>
		protected void DrawStar (CGContext context, float starDiameter)
		{
			// declare vars
			// 144º
			float theta = 2 * (float)Math.PI * (2f / 5f);
			float radius = starDiameter / 2;

			// move up and over
			context.TranslateCTM (starDiameter / 2, starDiameter / 2);

			context.MoveTo (0, radius);
			for (int i = 1; i < 5; i++) {
				context.AddLineToPoint (radius * (float)Math.Sin (i * theta), radius * (float)Math.Cos (i * theta));
			}
			//context.SetRGBFillColor (1, 1, 1, 1);
			context.ClosePath ();
			context.FillPath ();
		}
开发者ID:CBrauer,项目名称:monotouch-samples,代码行数:21,代码来源:CameraOverlayView.cs

示例5: DrawStarPattern

		/// <summary>
		/// This is a slightly more complicated draw pattern, but using it is just 
		/// as easy as the previous one. To use this one, simply change "DrawPolkaDotPattern"
		/// in line 54 above to "DrawStarPattern"
		/// </summary>
		protected void DrawStarPattern (CGContext context)
		{
			// declare vars
			float starDiameter = 16;
			// 144º
			float theta = 2 * (float)Math.PI * (2f / 5f);
			float radius = starDiameter / 2;
			
			// move up and over
			context.TranslateCTM (starDiameter / 2, starDiameter / 2);
			
			context.MoveTo (0, radius);
			for (int i = 1; i < 5; i++) {
				context.AddLineToPoint (radius * (float)Math.Sin (i * theta), radius * (float)Math.Cos (i * theta));
			}
			// fill our star as dark gray
			context.ClosePath ();
			context.FillPath ();
		}
开发者ID:GSerjo,项目名称:monotouch-samples,代码行数:24,代码来源:Controller.cs

示例6: 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

示例7: 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

示例8: DrawFlag

		protected void DrawFlag (CGContext context)
		{
			// declare vars
			int i, j;
			
			// general sizes
			float flagWidth = imageView.Frame.Width * .8f;
			float flagHeight = (float)(flagWidth / 1.9);
			PointF flagOrigin = new PointF (imageView.Frame.Width * .1f, imageView.Frame.Height / 3);
			
			// stripe
			float stripeHeight = flagHeight / 13;
			float stripeSpacing = stripeHeight * 2;
			RectangleF stripeRect = new RectangleF (0, 0, flagWidth, stripeHeight);
			
			// star field
			float starFieldHeight = 7 * stripeHeight;
			float starFieldWidth = flagWidth * (2f / 5f);
			RectangleF starField = new RectangleF (flagOrigin.X, flagOrigin.Y + (6 * stripeHeight), starFieldWidth, starFieldHeight);
			
			// stars
			float starDiameter = flagHeight * 0.0616f;
			float starHorizontalCenterSpacing = (starFieldWidth / 6);
			float starHorizontalPadding = (starHorizontalCenterSpacing / 4);
			float starVerticalCenterSpacing = (starFieldHeight / 5);
			float starVerticalPadding = (starVerticalCenterSpacing / 4);
			PointF firstStarOrigin = new PointF (flagOrigin.X + starHorizontalPadding, flagOrigin.Y + flagHeight - starVerticalPadding - (starVerticalCenterSpacing / 2));
			PointF secondRowFirstStarOrigin = new PointF (firstStarOrigin.X + (starHorizontalCenterSpacing / 2), firstStarOrigin.Y - (starVerticalCenterSpacing / 2));
			
			// white background + shadow
			context.SaveState ();
			context.SetShadow (new SizeF (15, -15), 7);
			context.SetFillColor (1, 1, 1, 1);
			context.FillRect (new RectangleF (flagOrigin.X, flagOrigin.Y, flagWidth, flagHeight));
			context.RestoreState ();
			
			// create a stripe layer
			using (CGLayer stripeLayer = CGLayer.Create (context, stripeRect.Size)) {
				
				// set red as the fill color
				// this works
				stripeLayer.Context.SetFillColor (1f, 0f, 0f, 1f);
				// but this doesn't ????
				//stripeLayer.Context.SetFillColor (new float[] { 1f, 0f, 0f, 1f });
				// fill the stripe
				stripeLayer.Context.FillRect (stripeRect);
				
				// loop through the stripes and draw the layer
				context.SaveState ();
				for (i = 0; i < 7; i++) {
					Console.WriteLine ("drawing stripe layer");
					// draw the layer
					context.DrawLayer (stripeLayer, flagOrigin);
					// move the origin
					context.TranslateCTM (0, stripeSpacing);
				}
				context.RestoreState ();
			}
			
			// draw the star field
			//BUGBUG: apple bug - this only works on on-screen CGContext and CGLayer
			//context.SetFillColor (new float[] { 0f, 0f, 0.329f, 1.0f });
			context.SetFillColor (0f, 0f, 0.329f, 1.0f);
			context.FillRect (starField);
			
			// create the star layer
			using (CGLayer starLayer = CGLayer.Create (context, starField.Size)) {
				
				// draw the stars
				DrawStar (starLayer.Context, starDiameter);
				
				// 6-star rows
				// save state so that as we translate (move the origin around, 
				// it goes back to normal when we restore)
				context.SaveState ();
				context.TranslateCTM (firstStarOrigin.X, firstStarOrigin.Y);
				// loop through each row
				for (j = 0; j < 5; j++) {
					
					// each star in the row
					for (i = 0; i < 6; i++) {
						
						// draw the star, then move the origin to the right
						context.DrawLayer (starLayer, new PointF (0f, 0f));
						context.TranslateCTM (starHorizontalCenterSpacing, 0f);
					}
					// move the row down, and then back left
					context.TranslateCTM ( (-i * starHorizontalCenterSpacing), -starVerticalCenterSpacing);
				}
				context.RestoreState ();
				
				// 5-star rows			
				context.SaveState ();
				context.TranslateCTM (secondRowFirstStarOrigin.X, secondRowFirstStarOrigin.Y);
				// loop through each row
				for (j = 0; j < 4; j++) {
					
					// each star in the row
					for (i = 0; i < 5; i++) {
						
//.........这里部分代码省略.........
开发者ID:BoogieMAN2K,项目名称:monotouch-samples,代码行数:101,代码来源:Controller.cs

示例9: Draw

        /// <summary>
        /// Draws the document page
        /// </summary>		
        private void Draw(CGContext context)
        {
            if (!PDFDocument.DocumentHasLoaded) {
                return;
            }

            // Draw page
            context.SetFillColor(1.0f, 1.0f, 1.0f, 1.0f);
            using (CGPDFPage pdfPage = PDFDocument.GetPage(mPageNumber)) {
                context.TranslateCTM(0, Bounds.Height);
                context.ScaleCTM(1.0f, -1.0f);
                context.ConcatCTM(pdfPage.GetDrawingTransform(CGPDFBox.Crop, Bounds, 0, true));
                context.SetRenderingIntent(CGColorRenderingIntent.Default);
                context.InterpolationQuality = CGInterpolationQuality.Default;
                context.DrawPDFPage(pdfPage);
            }
        }
开发者ID:xuanvu,项目名称:mTouch-PDFReader,代码行数:20,代码来源:PageContentView.cs

示例10: EraseStart

        public void EraseStart()
        {
            if (drawingBoard == null)
                return;

            UIGraphics.BeginImageContext (drawingBoard.Size);

            // erase lines
            ctx = UIGraphics.GetCurrentContext ();

            // Convert co-ordinate system to Cocoa's (origin in UL, not LL)
            ctx.TranslateCTM (0, drawingBoard.Size.Height);
            ctx.ConcatCTM (CGAffineTransform.MakeScale (1, -1));

            ctx.DrawImage (new RectangleF (0, 0, drawingBoard.Size.Width, drawingBoard.Size.Height),
                        drawingBoard.CGImage);
        }
开发者ID:sichy,项目名称:DrawingHelperSample,代码行数:17,代码来源:DrawingHelper.cs

示例11: AddRoundedRectToPath

		public static void AddRoundedRectToPath(CGContext context, RectangleF rect, float ovalWidth, float ovalHeight)
		{
			float fw, fh;
			if (ovalWidth == 0 || ovalHeight == 0)
			{
				context.AddRect(rect);
				return;
			}
			context.SaveState();
			context.TranslateCTM(rect.GetMinX(), rect.GetMinY());
			context.ScaleCTM(ovalWidth, ovalHeight);
			fw = rect.Width / ovalWidth;
			fh = rect.Height / ovalHeight;
			context.MoveTo(fw, fh / 2);
			context.AddArcToPoint(fw, fh, fw / 2, fh, 1);
			context.AddArcToPoint(0, fh, 0, fh / 2, 1);
			context.AddArcToPoint(0, 0, fw / 2, 0, 1);
			context.AddArcToPoint(fw, 0, fw, fh / 2, 1);
			context.ClosePath();
			context.RestoreState();
		}
开发者ID:modulexcite,项目名称:artapp,代码行数:21,代码来源:ImageHelper.cs

示例12: drawLabel

        void drawLabel(CGContext ctx, CGRect rect, nfloat yCoord, nfloat xCoord, CTTextAlignment alignment, UIColor color, string label, bool flipContext = true)
        {
            Console.WriteLine("Finish Draw code");

            var attrString = new NSMutableAttributedString (label);

            var range = new NSRange (0, attrString.Length);

            var uiFont = UIFont.FromName("HelveticaNeue-Medium", range.Length > 1 ? 15 : 22);

            var font = new CTFont (uiFont.Name, uiFont.PointSize);  //((uiFont.Name as NSString) as CFString, uiFont.pointSize, nil);

            var path = new CGPath ();

            var alignStyle = new CTParagraphStyle (new CTParagraphStyleSettings { Alignment = alignment });

            var attributes = new CTStringAttributes {
                Font = font,
                ForegroundColor = color.CGColor,
                ParagraphStyle = alignStyle
            };

            attrString.SetAttributes(attributes, new NSRange (0, attrString.Length));

            var target = new CGSize (nfloat.MaxValue, nfloat.MaxValue);

            var fit = new NSRange (0, 0);

            var framesetter = new CTFramesetter (attrString);

            var frameSize = framesetter.SuggestFrameSize(range, null, target, out fit);

            var textRect = new CGRect (xCoord - (frameSize.Width / 2), yCoord - (frameSize.Height / 2), frameSize.Width, frameSize.Height);

            path.AddRect(textRect);

            var frame = framesetter.GetFrame(range, path, null);

            if (flipContext) {

                ctx.SaveState();

                ctx.TranslateCTM(0, rect.Height);

                ctx.ScaleCTM(1, -1);

                frame.Draw(ctx);

                ctx.RestoreState();

            } else {
                frame.Draw(ctx);
            }
        }
开发者ID:colbylwilliams,项目名称:bugtrap,代码行数:54,代码来源:BtAnnotateImageView.cs

示例13: drawLabel

		void drawLabel (CGContext ctx, CGRect rect, nfloat yCoord, nfloat xCoord, UITextAlignment alignment, string label, bool flipContext = true, bool centerVertical = false)
		{
			// Draw light the sunrise and Sunset labels at the ends of the light box
			using (UIColor fontColor = UIColor.White, shadowColor = UIColor.Black.ColorWithAlpha (0.1f)) {

				var fontAttributes = new UIFontAttributes (new UIFontFeature (CTFontFeatureNumberSpacing.Selector.ProportionalNumbers));

				using (var desc = UIFont.SystemFontOfSize (fontSize).FontDescriptor.CreateWithAttributes (fontAttributes)) {

					using (UIFont font = UIFont.FromDescriptor (desc, fontSize)) {

						// calculating the range of our attributed string
						var range = new NSRange (0, label.Length);

						// set justification for text block
						using (var alignStyle = new NSMutableParagraphStyle { Alignment = alignment }) {

							// add stylistic attributes to out attributed string
							var stringAttributes = new UIStringAttributes {
								ForegroundColor = fontColor,
								Font = font,
								ParagraphStyle = alignStyle
							};

							var target = new CGSize (float.MaxValue, float.MaxValue);

							NSRange fit;

							using (NSMutableAttributedString attrString = new NSMutableAttributedString (label, stringAttributes)) {

								//creating a container for out attributed string 
								using (CTFramesetter framesetter = new CTFramesetter (attrString)) {


									CGSize frameSize = framesetter.SuggestFrameSize (range, null, target, out fit);


									if (alignment == UITextAlignment.Center) xCoord -= (frameSize.Width / 2);

									if (alignment == UITextAlignment.Right) xCoord -= frameSize.Width;


									// subtract the frameSize so the flipped context behaves as expected
									yCoord -= frameSize.Height;

									if (centerVertical) yCoord += (frameSize.Height / 2);


									var textRect = new CGRect (xCoord, yCoord, frameSize.Width, frameSize.Height);

									using (CGPath path = new CGPath ()) {

										path.AddRect (textRect);

										ctx.SetShadow (new CGSize (0.0f, 1.0f), 0.0f, shadowColor.CGColor);

										using (CTFrame frame = framesetter.GetFrame (range, path, null)) {

											if (flipContext) {

												ctx.SaveState ();
												ctx.TranslateCTM (0, rect.Height);
												ctx.ScaleCTM (1, -1);

												frame.Draw (ctx);

												ctx.RestoreState ();

											} else {

												frame.Draw (ctx);
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
开发者ID:colbylwilliams,项目名称:XWeather,代码行数:81,代码来源:DailyGraphView.cs

示例14: DrawText

        private void DrawText(string text, CGContext context, RectangleF bounds, bool withShadow)
        {
            // save state and transform
            context.SaveState ();
            context.TranslateCTM (0, bounds.Height);
            context.ScaleCTM (1.0f, -1.0f);

            // calculate location
            context.SelectFont("Helvetica", UIFont.LabelFontSize,CGTextEncoding.MacRoman);
            NSString t = new NSString(text);
            var font = UIFont.FromName("Helvetica", UIFont.LabelFontSize);
            var size = t.StringSize(font);
            var x = bounds.Left;
            var y = bounds.Height/2 - size.Height/2;

            // draw the shadow at an offset
            if (withShadow) {
                UIColor.FromRGB(193,193,193).SetFill();
                context.ShowTextAtPoint(x+1, y+4, text);
            }

            // draw the text
            if (_parentCell.Highlighted && !_menuItem.IsHeader)
                _headerForegroundColor.SetFill ();
            else if (_menuItem.IsHeader)
                _headerForegroundColor.SetFill ();
            else
                _foregroundColor.SetFill();
            context.ShowTextAtPoint(x, y+5, text);

            // restore context
            context.RestoreState();
        }
开发者ID:redbitdev,项目名称:socialcloud-mobile,代码行数:33,代码来源:MainMenuTableViewCell.cs

示例15: DrawImage

 private void DrawImage(UIImage image, CGContext context, RectangleF bounds)
 {
     // required hack to get the images to draw rightside up
     context.SaveState();
     context.TranslateCTM(0, bounds.Height);
     context.ScaleCTM(1.0f, -1.0f);
     bounds.Y = -bounds.Y;
     context.DrawImage(bounds, image.CGImage);
     context.RestoreState();
 }
开发者ID:redbitdev,项目名称:socialcloud-mobile,代码行数:10,代码来源:MainMenuTableViewCell.cs


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