本文整理汇总了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();
}
示例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();
}
示例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 ();
}
示例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 ();
}
示例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();
}
示例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 ();
}
示例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();
}
示例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;
}
示例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 ();
}
示例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));
}
示例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();
}
}
示例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();
}
示例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 ();
}
示例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();
}
示例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();
}