本文整理汇总了C#中MonoMac.CoreGraphics.CGContext类的典型用法代码示例。如果您正苦于以下问题:C# CGContext类的具体用法?C# CGContext怎么用?C# CGContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CGContext类属于MonoMac.CoreGraphics命名空间,在下文中一共展示了CGContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderGlyphToContext
public static void RenderGlyphToContext (CGContext context, PointF position, Glyph g, Fnt font, byte[] palette, int offset)
{
byte[] buf = new byte[g.Width * g.Height * 4];
int i = 0;
for (int y = g.Height - 1; y >= 0; y--) {
for (int x = g.Width - 1; x >= 0; x--) {
if (g.Bitmap[y,x] == 0)
buf [i + 0] = 0;
else if (g.Bitmap[y,x] == 1)
buf [i + 0] = 255;
else
buf [i + 0] = 128;
buf[i + 1] = palette[ (g.Bitmap[y,x]) * 3 + offset + 0];
buf[i + 2] = palette[ (g.Bitmap[y,x]) * 3 + offset + 1];
buf[i + 3] = palette[ (g.Bitmap[y,x]) * 3 + offset + 2];
if (buf[i+1] == 252 && buf[i+2] == 0 && buf[i+3] == 252)
buf[i + 0] = 0;
i += 4;
}
}
CGImage glyphImage = CreateImage (buf, (ushort)g.Width, (ushort)g.Height, 32, g.Width * 4);
context.DrawImage (new RectangleF (position, new SizeF (g.Width, g.Height)), glyphImage);
}
示例2: Graphics
public Graphics(CGContext context, bool flipped = true)
{
if (context == null)
throw new ArgumentNullException ("context");
isFlipped = flipped;
InitializeContext(context);
}
示例3: CocoaGraphDrawer
public CocoaGraphDrawer(CGContext g, int w, int h)
{
this.g = g;
this.w = w;
this.h = h;
g.SetAllowsAntialiasing(true);
g.InterpolationQuality = CGInterpolationQuality.High;
}
示例4: DrawInContext
public override void DrawInContext (CGContext context)
{
base.DrawInContext (context);
context.AddEllipseInRect (Bounds);
context.SetFillColor (ClockColor);
context.FillPath ();
}
示例5: FillEllipsis
public static void FillEllipsis(CGContext context, RectangleF rect, CGColor color, float lineWidth)
{
context.SaveState();
context.SetFillColor(color);
context.AddEllipseInRect(rect);
context.FillPath();
context.RestoreState();
}
示例6: GraphicsContextWrapper
public GraphicsContextWrapper(CGContext context, float boundsWidth, float boundsHeight, BasicRectangle dirtyRect)
{
Context = context;
BoundsWidth = boundsWidth;
BoundsHeight = boundsHeight;
DirtyRect = dirtyRect;
Density = GetDisplayScale();
}
示例7: 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();
}
示例8: 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();
}
示例9: DrawRect
public static void DrawRect(CGContext context, RectangleF rect, CGColor color, float lineWidth)
{
context.SaveState();
context.AddRect(rect);
context.Clip();
context.SetLineWidth(lineWidth);
context.SetStrokeColor(color);
context.StrokeRect(rect);
context.RestoreState();
}
示例10: Draw
internal static void Draw (CGContext ctx, GradientInfo gradient)
{
ctx.SaveState ();
ctx.Clip ();
using (var cg = new CGGradient (Util.DeviceRGBColorSpace, gradient.Colors.ToArray (), gradient.Stops.ToArray ())) {
if (gradient.Linear)
ctx.DrawLinearGradient (cg, gradient.Start, gradient.End, CGGradientDrawingOptions.DrawsBeforeStartLocation | CGGradientDrawingOptions.DrawsAfterEndLocation);
else
ctx.DrawRadialGradient (cg, gradient.Start, gradient.StartRadius, gradient.End, gradient.EndRadius, CGGradientDrawingOptions.DrawsBeforeStartLocation | CGGradientDrawingOptions.DrawsAfterEndLocation);
}
ctx.RestoreState ();
}
示例11: CoreGraphicsRenderContext
/// <summary>
/// Initializes a new instance of the <see cref="CoreGraphicsRenderContext"/> class.
/// </summary>
/// <param name="context">The context.</param>
public CoreGraphicsRenderContext(CGContext context)
{
this.gctx = context;
// Set rendering quality
this.gctx.SetAllowsFontSmoothing (true);
this.gctx.SetAllowsFontSubpixelQuantization (true);
this.gctx.SetAllowsAntialiasing (true);
this.gctx.SetShouldSmoothFonts (true);
this.gctx.SetShouldAntialias (true);
this.gctx.InterpolationQuality = CGInterpolationQuality.High;
this.gctx.SetTextDrawingMode (CGTextDrawingMode.Fill);
this.gctx.TextMatrix = CGAffineTransform.MakeScale (1, 1);
}
示例12: MeasureStringWidth
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;
}
示例13: DrawText
public static void DrawText(CGContext context, string text, string fontName, float fontSize, float translateHeight, float x, float y)
{
context.SaveState();
context.SelectFont(fontName, fontSize, CGTextEncoding.MacRoman);
context.SetTextDrawingMode(CGTextDrawingMode.Fill);
context.SetFillColor(new CGColor(1, 1));
context.SetStrokeColor(new CGColor(1.0f, 1.0f));
//context.AddRect(rectText);
//context.Clip();
context.TextMatrix = CGAffineTransform.MakeScale(1.0f, -1.0f);
context.TranslateCTM(0, translateHeight);
context.ScaleCTM(1, -1);
context.ShowTextAtPoint(x, y, text);
context.RestoreState();
}
示例14: DrawTextInRect
public static void DrawTextInRect(CGContext context, RectangleF rect, string text, string fontName, float fontSize, NSColor fontColor)
{
context.SaveState();
NSString str = new NSString(text);
var dict = new NSMutableDictionary();
dict.Add(NSAttributedString.ForegroundColorAttributeName, fontColor);
dict.Add(NSAttributedString.FontAttributeName, NSFont.FromFontName(fontName, fontSize));
str.DrawString(rect, dict);
context.RestoreState();
}
示例15: MeasureText
public static SizeF MeasureText(CGContext context, string text, string fontName, float fontSize)
{
NSString str = new NSString(text);
var dict = new NSMutableDictionary();
dict.Add(NSAttributedString.FontAttributeName, NSFont.FromFontName(fontName, fontSize));
var size = str.StringSize(dict);
return size;
}