• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# CoreGraphics.CGContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



CGContext类属于MonoMac.CoreGraphics命名空间,在下文中一共展示了CGContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
		}
开发者ID:carriercomm,项目名称:scsharp,代码行数:29,代码来源:GuiUtil.cs


示例2: Graphics

 public Graphics(CGContext context, bool flipped = true)
 {
     if (context == null)
         throw new ArgumentNullException ("context");
     isFlipped = flipped;
     InitializeContext(context);
 }
开发者ID:stnk3000,项目名称:sysdrawing-coregraphics,代码行数:7,代码来源:Graphics.cs


示例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;
 }
开发者ID:ivynetca,项目名称:lapsestudio,代码行数:8,代码来源:CocoaGraphDrawer.cs


示例4: DrawInContext

		public override void DrawInContext (CGContext context)
		{
			base.DrawInContext (context);
			
			context.AddEllipseInRect (Bounds);
			context.SetFillColor (ClockColor);
			context.FillPath ();
		}
开发者ID:Anomalous-Software,项目名称:monomac,代码行数:8,代码来源:ClockLayer.cs


示例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();
 }
开发者ID:pascalfr,项目名称:MPfm,代码行数:8,代码来源:CoreGraphicsHelper.cs


示例6: GraphicsContextWrapper

 public GraphicsContextWrapper(CGContext context, float boundsWidth, float boundsHeight, BasicRectangle dirtyRect)
 {
     Context = context;
     BoundsWidth = boundsWidth;
     BoundsHeight = boundsHeight;
     DirtyRect = dirtyRect;
     Density = GetDisplayScale();
 }
开发者ID:pascalfr,项目名称:MPfm,代码行数:8,代码来源:GraphicsContextWrapper.cs


示例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();
 }
开发者ID:pascalfr,项目名称:MPfm,代码行数:9,代码来源:CoreGraphicsHelper.cs


示例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();
 }
开发者ID:pascalfr,项目名称:MPfm,代码行数:9,代码来源:CoreGraphicsHelper.cs


示例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();
 }
开发者ID:pascalfr,项目名称:MPfm,代码行数:10,代码来源:CoreGraphicsHelper.cs


示例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 ();
		}
开发者ID:m13253,项目名称:xwt,代码行数:12,代码来源:GradientBackendHandler.cs


示例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);
        }
开发者ID:trinnguyen,项目名称:oxyplot-xammac,代码行数:18,代码来源:CoreGraphicsRenderContext.cs


示例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;
        }
开发者ID:pascalfr,项目名称:MPfm,代码行数:18,代码来源:CoreGraphicsHelper.cs


示例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();
 }
开发者ID:pascalfr,项目名称:MPfm,代码行数:15,代码来源:CoreGraphicsHelper.cs


示例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();
 }
开发者ID:pascalfr,项目名称:MPfm,代码行数:10,代码来源:CoreGraphicsHelper.cs


示例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;
 }
开发者ID:pascalfr,项目名称:MPfm,代码行数:8,代码来源:CoreGraphicsHelper.cs


示例16: EOFillPath

 public static void EOFillPath(CGContext context, CGPath path, CGColor color)
 {
     context.SaveState();
     context.SetFillColor(color);
     context.AddPath(path);
     context.EOFillPath();
     context.RestoreState();
 }
开发者ID:pascalfr,项目名称:MPfm,代码行数:8,代码来源:CoreGraphicsHelper.cs


示例17: FillGradient

 public static void FillGradient(CGContext context, RectangleF rect, CGColor color1, CGColor color2, bool isHorizontal)
 {
     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);
     if(isHorizontal)
         context.DrawLinearGradient(gradientBackground, new PointF(rect.X, rect.Y), new PointF(rect.X + rect.Width, rect.Y + rect.Height), CGGradientDrawingOptions.DrawsBeforeStartLocation);
     else
         context.DrawLinearGradient(gradientBackground, new PointF(0, 0), new PointF(0, rect.Height), CGGradientDrawingOptions.DrawsBeforeStartLocation);
     context.RestoreState();
 }       
开发者ID:pascalfr,项目名称:MPfm,代码行数:21,代码来源:CoreGraphicsHelper.cs


示例18: RasterizeTriangle

        /// <summary>
        /// Rasterizes the triangle specified by the vector / points and their associated colors
        /// using barycentric coordinates.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="vt1"></param>
        /// <param name="vt2"></param>
        /// <param name="vt3"></param>
        /// <param name="colorV1"></param>
        /// <param name="colorV2"></param>
        /// <param name="colorV3"></param>
        internal void RasterizeTriangle(CGContext context, PointF vt1, PointF vt2, PointF vt3, Color colorV1, Color colorV2, Color colorV3)
        {
            // get the bounding box of the triangle
            int maxX = (int)Math.Max(vt1.X, Math.Max(vt2.X, vt3.X));
            int minX = (int)Math.Min(vt1.X, Math.Min(vt2.X, vt3.X));
            int maxY = (int)Math.Max(vt1.Y, Math.Max(vt2.Y, vt3.Y));
            int minY = (int)Math.Min(vt1.Y, Math.Min(vt2.Y, vt3.Y));

            // Barycentric coordinates at minX/minY corner
            PointF pm = new PointF( minX, minY );

            var edge32 = new Edge(vt3, vt2, vt1, pm, colorV1);
            var edge13 = new Edge (vt1, vt3, vt2, pm, colorV2);
            var edge21 = new Edge (vt2, vt1, vt3, pm, colorV3);

            int span32 = edge32.EdgeOrigin;
            int span13 = edge13.EdgeOrigin;
            int span21 = edge21.EdgeOrigin;

            edge32Red = colorV1.R;
            edge32Green = colorV1.G;
            edge32Blue = colorV1.B;
            edge32Alpha = colorV1.A;

            edge13Red = colorV2.R;
            edge13Green = colorV2.G;
            edge13Blue = colorV2.B;
            edge13Alpha = colorV2.A;

            edge21Red = colorV3.R;
            edge21Green = colorV3.G;
            edge21Blue = colorV3.B;
            edge21Alpha = colorV3.A;

            int span32XOffset = 0;
            int span13XOffset = 0;
            int span21XOffset = 0;

            bool inside = false;
            int mask = 0;
            //  Iterate over each pixel of bounding box and check if it's inside
            //  the triangle using the barycentirc approach.
            for (int y = minY; y <= maxY; y += Edge.StepYSize)
            {
                // Barycentric coordinates at start of row
                span32XOffset = span32;
                span13XOffset = span13;
                span21XOffset = span21;

                inside = false;
                for (int x = minX; x <= maxX; x += Edge.StepXSize)
                {

                    mask = span32XOffset | span13XOffset | span21XOffset;

                    // If p is on or inside all edges for any pixels,
                    // render those pixels.
                    if (mask >= 0)
                    {
                        if (!inside)
                        {
                            inside = true;
                        }
                        RenderPixels(context, x, y, edge32, edge13, edge21, span32XOffset, span13XOffset, span21XOffset);
                    }

                    // Step to the right
                    span32XOffset += edge32.StepX;
                    span13XOffset += edge13.StepX;
                    span21XOffset += edge21.StepX;
                    if (mask < 0 && inside)
                    {
                        inside = false;
                        break;
                    }

                }

                // Row step
                span32 += edge32.StepY;
                span13 += edge13.StepY;
                span21 += edge21.StepY;
            }
        }
开发者ID:asfungithub,项目名称:sysdrawing-coregraphics,代码行数:95,代码来源:PathGradientBrush.cs


示例19: StrokePath

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


示例20: RenderPixels

        void RenderPixels(CGContext context, int x, int y, Edge edge32, Edge edge13, Edge edge21, int w1, int w2, int w3)
        {
            //VertexInterpoliation = A * x + B * y + C;
            //			float alpha = (edge32.A * x + edge32.B * y + edge32.C) * edge32.VertexFactor;
            //			float beta = (edge13.A * x + edge13.B * y + edge13.C)  * edge13.VertexFactor;
            //			float gamma = (edge21.A * x + edge21.B * y + edge21.C) * edge21.VertexFactor;

            // Determine barycentric coordinates
            float alpha = (float)(w1 * edge32.VertexFactor);
            float beta = (float)(w2 * edge13.VertexFactor);
            float gamma = (float)(w3 * edge21.VertexFactor);

            GradientLerp3 (alpha, beta, gamma);
            // Set the color
            context.SetFillColor (colorOutput [0], colorOutput [1], colorOutput [2], colorOutput [3]);

            // Set our pixel location
            pixelRect.X = x;
            pixelRect.Y = y;

            // Fill the pixel
            context.FillRect (pixelRect);
        }
开发者ID:asfungithub,项目名称:sysdrawing-coregraphics,代码行数:23,代码来源:PathGradientBrush.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Foundation.NSAutoreleasePool类代码示例发布时间:2022-05-26
下一篇:
C# CoreGraphics.CGAffineTransform类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap