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


C# CGBitmapContext.SetRGBFillColor方法代码示例

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


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

示例1: DrawScreen

		protected void DrawScreen ()
		{
			
			// create our offscreen bitmap context
			// size
			SizeF bitmapSize = new SizeF (imageView.Frame.Size);
			using (CGBitmapContext context = new CGBitmapContext (IntPtr.Zero, (int)bitmapSize.Width, (int)bitmapSize.Height, 8, (int)(4 * bitmapSize.Width), CGColorSpace.CreateDeviceRGB (), CGImageAlphaInfo.PremultipliedFirst)) {

				// save the state of the context while we change the CTM
				context.SaveState ();
				
				// draw our circle
				context.SetRGBFillColor (1, 0, 0, 1);
				context.TranslateCTM (currentLocation.X, currentLocation.Y);
				context.RotateCTM (currentRotation);
				context.ScaleCTM (currentScale, currentScale);
				context.FillRect (new RectangleF (-10, -10, 20, 20));
				
				// restore our transformations
				context.RestoreState ();

				// draw our coordinates for reference
				DrawCoordinateSpace (context);
				
				// output the drawing to the view
				imageView.Image = UIImage.FromImage (context.ToImage ());
			}
		}
开发者ID:rojepp,项目名称:monotouch-samples,代码行数:28,代码来源:Controller.cs

示例2: AdjustImage

        public static UIImage AdjustImage(RectangleF rect, UIImage template, CGBlendMode mode, float red, float green, float blue, float alpha)
        {
            using (var cs = CGColorSpace.CreateDeviceRGB ())
            {
                using (var context = new CGBitmapContext (IntPtr.Zero, (int)rect.Width, (int)rect.Height, 8, (int)rect.Height * 4, cs, CGImageAlphaInfo.PremultipliedLast))
                {

                    context.TranslateCTM (0.0f, 0f);
                    //context.ScaleCTM(1.0f,-1.0f);
                    context.DrawImage (rect, template.CGImage);
                    context.SetBlendMode (mode);
                    context.ClipToMask (rect, template.CGImage);
                    context.SetRGBFillColor (red, green, blue, alpha);
                    context.FillRect (rect);

                    return UIImage.FromImage (context.ToImage ());
                }
            }
        }
开发者ID:Clancey,项目名称:ClanceyLib,代码行数:19,代码来源:Graphics.cs

示例3: MakeCalendarBadge

        public static UIImage MakeCalendarBadge(UIImage template, string smallText, string bigText)
        {
            using (var cs = CGColorSpace.CreateDeviceRGB ()){
                using (var context = new CGBitmapContext (IntPtr.Zero, 57, 57, 8, 57*4, cs, CGImageAlphaInfo.PremultipliedLast)){
                    //context.ScaleCTM (0.5f, -1);
                    context.TranslateCTM (0, 0);
                    context.DrawImage (new RectangleF (0, 0, 57, 57), template.CGImage);
                    context.SetRGBFillColor (1, 1, 1, 1);

                    context.SelectFont ("Helvetica", 10f, CGTextEncoding.MacRoman);

                    // Pretty lame way of measuring strings, as documented:
                    var start = context.TextPosition.X;
                    context.SetTextDrawingMode (CGTextDrawingMode.Invisible);
                    context.ShowText (smallText);
                    var width = context.TextPosition.X - start;

                    //var ns = new NSString (smallText);
                    //UIFont ff = UIFont.FromName ("Helvetica", 10);

                    context.SetTextDrawingMode (CGTextDrawingMode.Fill);
                    context.ShowTextAtPoint ((57-width)/2, 46, smallText);

                    // The big string
                    context.SelectFont ("Helvetica-Bold", 32, CGTextEncoding.MacRoman);
                    start = context.TextPosition.X;
                    context.SetTextDrawingMode (CGTextDrawingMode.Invisible);
                    context.ShowText (bigText);
                    width = context.TextPosition.X - start;

                    context.SetRGBFillColor (0, 0, 0, 1);
                    context.SetTextDrawingMode (CGTextDrawingMode.Fill);
                    context.ShowTextAtPoint ((57-width)/2, 9, bigText);

                    context.StrokePath ();

                    return UIImage.FromImage (context.ToImage ());
                }
            }
        }
开发者ID:rsatter,项目名称:MonoCross,代码行数:40,代码来源:ElementBadge.cs

示例4: Render

        /// <summary>
        /// Render the current complete scene.
        /// </summary>
        void Render()
        {
            try
            {
                lock (_renderSynchronisation)
                {
                    RectangleF rect = _rect;

                    // create the view.
                    View2D view = _cacheRenderer.Create((int)(rect.Width * _extra), (int)(rect.Height * _extra),
                                      this.Map, (float)this.Map.Projection.ToZoomFactor(this.MapZoom),
                                      this.MapCenter, _invertX, _invertY, this.MapTilt);
                    if (rect.Width == 0)
                    { // only render if a proper size is known.
                        return;
                    }

                    // calculate width/height.
                    int imageWidth = (int)(rect.Width * _extra * _scaleFactor);
                    int imageHeight = (int)(rect.Height * _extra * _scaleFactor);

                    // create a new bitmap context.
                    CGColorSpace space = CGColorSpace.CreateDeviceRGB();
                    int bytesPerPixel = 4;
                    int bytesPerRow = bytesPerPixel * imageWidth;
                    int bitsPerComponent = 8;

                    // get old image if available.
                    CGBitmapContext image = new CGBitmapContext(null, imageWidth, imageHeight,
                                                bitsPerComponent, bytesPerRow,
                                                space, // kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipLast
                                                CGBitmapFlags.PremultipliedFirst | CGBitmapFlags.ByteOrder32Big);

                    long before = DateTime.Now.Ticks;

                    // build the layers list.
                    var layers = new List<Layer>();
                    for (int layerIdx = 0; layerIdx < this.Map.LayerCount; layerIdx++)
                    {
                        layers.Add(this.Map[layerIdx]);
                    }

                    // add the internal layer.
                    try
                    {
                        image.SetRGBFillColor(1, 1, 1, 1);
                        image.FillRect(new RectangleF(
                            0, 0, imageWidth, imageHeight));

                        // notify the map that the view has changed.
                        this.Map.ViewChanged((float)this.Map.Projection.ToZoomFactor(this.MapZoom), this.MapCenter,
                            view);
                        long afterViewChanged = DateTime.Now.Ticks;
                        OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", TraceEventType.Information,
                            "View change took: {0}ms @ zoom level {1}",
                            (new TimeSpan(afterViewChanged - before).TotalMilliseconds), this.MapZoom);

                        float sceneZoomFactor = (float)this.Map.Projection.ToZoomFactor(this.MapZoom);

                        // does the rendering.
                        bool complete = _cacheRenderer.Render(new CGContextWrapper(image,
                                            new RectangleF(0, 0, (int)(rect.Width * _extra), (int)(rect.Height * _extra))),
                                            layers, view, sceneZoomFactor);

                        long afterRendering = DateTime.Now.Ticks;
                        OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", TraceEventType.Information,
                            "Rendering took: {0}ms @ zoom level {1}",
                            (new TimeSpan(afterRendering - afterViewChanged).TotalMilliseconds), this.MapZoom);

                        if (complete)
                        { // there was no cancellation, the rendering completely finished.
                            lock (_bufferSynchronisation)
                            {
                                if (_onScreenBuffer != null &&
                                    _onScreenBuffer.Tag != null)
                                { // on screen buffer.
                                    (_onScreenBuffer.Tag as CGImage).Dispose();
                                }

                                // add the newly rendered image again.
                                _onScreenBuffer = new ImageTilted2D(view.Rectangle, new byte[0], float.MinValue, float.MaxValue);
                                _onScreenBuffer.Tag = image.ToImage();

                                // store the previous view.
                                _previousRenderedZoom = view;
                            }

                            this.InvokeOnMainThread(InvalidateMap);
                        }

                        long after = DateTime.Now.Ticks;
                        OsmSharp.Logging.Log.TraceEvent("OsmSharp.iOS.UI.MapView", TraceEventType.Information,
                            "Rendering in {0}ms", new TimeSpan(after - before).TotalMilliseconds);
                    }
                    finally
                    {

//.........这里部分代码省略.........
开发者ID:nubix-biz,项目名称:OsmSharp,代码行数:101,代码来源:MapView.cs

示例5: Render

        /// <summary>
        /// Render the current complete scene.
        /// </summary>
        void Render()
        {
            try
            {
                if (Monitor.TryEnter(_cacheRenderer, 1000))
                {
                    try
                    {
                            // use object
                        RectangleF rect = _rect;

                        // create the view.
                        float size = System.Math.Max(_rect.Width, _rect.Height);
                        var view = _cacheRenderer.Create((int)(size * _extra), (int)(size * _extra),
                                          this.Map, (float)this.Map.Projection.ToZoomFactor(this.MapZoom),
                                          this.MapCenter, _invertX, _invertY, this.MapTilt);
                        if (rect.Width == 0)
                        { // only render if a proper size is known.
                            return;
                        }

                        // calculate width/height.
                        int imageWidth = (int)(size * _extra * _scaleFactor);
                        int imageHeight = (int)(size * _extra * _scaleFactor);

                        // create a new bitmap context.
                        CGColorSpace space = CGColorSpace.CreateDeviceRGB();
                        int bytesPerPixel = 4;
                        int bytesPerRow = bytesPerPixel * imageWidth;
                        int bitsPerComponent = 8;

                        // get old image if available.
                        CGBitmapContext image = new CGBitmapContext(null, imageWidth, imageHeight,
                                                    bitsPerComponent, bytesPerRow,
                                                    space, // kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipLast
                                                    CGBitmapFlags.PremultipliedFirst | CGBitmapFlags.ByteOrder32Big);

                        long before = DateTime.Now.Ticks;

                        // build the layers list.
                        var layers = new List<Layer>();
                        for (int layerIdx = 0; layerIdx < this.Map.LayerCount; layerIdx++)
                        {
                            layers.Add(this.Map[layerIdx]);
                        }

                        // add the internal layer.
                        try
                        {
                            image.SetRGBFillColor(1, 1, 1, 1);
                            image.FillRect(new RectangleF(
                                0, 0, imageWidth, imageHeight));

                            // notify the map that the view has changed.
                            var normalView = _cacheRenderer.Create(_rect.Width, _rect.Height,
                                              this.Map, (float)this.Map.Projection.ToZoomFactor(this.MapZoom),
                                              this.MapCenter, _invertX, _invertY, this.MapTilt);
                            this.Map.ViewChanged((float)this.Map.Projection.ToZoomFactor(this.MapZoom), this.MapCenter,
                                normalView, view);
                            long afterViewChanged = DateTime.Now.Ticks;
                            OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", TraceEventType.Information,
                                "View change took: {0}ms @ zoom level {1}",
                                (new TimeSpan(afterViewChanged - before).TotalMilliseconds), this.MapZoom);

                            float zoomFactor = this.MapZoom;
                            float sceneZoomFactor = (float)this.Map.Projection.ToZoomFactor(this.MapZoom);

                            // does the rendering.
                            bool complete = _cacheRenderer.Render(new CGContextWrapper(image,
                                new RectangleF(0, 0, (int)(size * _extra), (int)(size * _extra))),
                                                _map.Projection, layers, view, sceneZoomFactor);

                            long afterRendering = DateTime.Now.Ticks;

                            if (complete)
                            { // there was no cancellation, the rendering completely finished.
                                lock (_bufferSynchronisation)
                                {
                                    if (_onScreenBuffer != null &&
                                        _onScreenBuffer.NativeImage != null)
                                    { // on screen buffer.
                                        _onScreenBuffer.NativeImage.Dispose();
                                    }

                                    // add the newly rendered image again.
                                    _onScreenBuffer = new ImageTilted2D(view.Rectangle,
                                        new NativeImage(image.ToImage()), float.MinValue, float.MaxValue);

                                    // store the previous view.
                                    _previouslyRenderedView = view;
                                }

                                // make sure this view knows that there is a new rendering.
                                this.InvokeOnMainThread(SetNeedsDisplay);
                            }

                            long after = DateTime.Now.Ticks;
//.........这里部分代码省略.........
开发者ID:kochizufan,项目名称:OsmSharp,代码行数:101,代码来源:MapView.cs

示例6: CreateTextBitmapContext

		CGBitmapContext CreateTextBitmapContext (string str, out byte[] bitmapData)
		{
			NSString text = new NSString (str);
			UIFont font = UIFont.FromName ("HelveticaNeue-Light", 128);
			SizeF size = text.StringSize (font);
			int width = (int)size.Width;
			int height = (int)size.Height;
			bitmapData = new byte[256*256*4];
			CGBitmapContext bitmapContext = new CGBitmapContext (bitmapData, 256, 256, 8, 256*4, CGColorSpace.CreateDeviceRGB (), CGImageAlphaInfo.PremultipliedLast);
			//Console.WriteLine ("bitmap context size: {0} x {1}", bitmapContext.Width, bitmapContext.Height);
			UIGraphics.PushContext (bitmapContext);
			float grayLevel = str == " " ? .8f : 1;
			bitmapContext.SetRGBFillColor (grayLevel, grayLevel, grayLevel, 1);
			bitmapContext.FillRect (new RectangleF (0, 0, 256.0f, 256.0f));
			bitmapContext.SetRGBFillColor (0, 0, 0, 1);

			text.DrawString (new PointF ((256.0f - width) / 2.0f, (256.0f - height) / 2.0f + font.Descender), font);
			UIGraphics.PopContext ();

			return bitmapContext;
		}
开发者ID:Adameg,项目名称:mobile-samples,代码行数:21,代码来源:EAGLView.cs


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