iOS Guides | Samples

MonoTouch.UIKit.UIGraphicsImageRenderer Class

A UIGraphicsRenderer that produces images (see UIGraphicsPDFRenderer).

See Also: UIGraphicsImageRenderer

Syntax

[MonoTouch.Foundation.Register("UIGraphicsImageRenderer", true)]
[MonoTouch.ObjCRuntime.Introduced(MonoTouch.ObjCRuntime.PlatformName.iOS, 10, 0, MonoTouch.ObjCRuntime.PlatformArchitecture.None, null)]
[MonoTouch.ObjCRuntime.Introduced(MonoTouch.ObjCRuntime.PlatformName.TvOS, 10, 0, MonoTouch.ObjCRuntime.PlatformArchitecture.None, null)]
public class UIGraphicsImageRenderer : UIGraphicsRenderer

Remarks

Introduced in iOS 10, the UIGraphicsImageRenderer allows custom drawing code that utilitizes wide color.

In versions prior to iOS 10, custom drawing was done by retrieving a CGContext, manipulating its state, and then retrieving the custom image. Now, the standard technique is to use UIGraphicsImageRenderer.CreateImage, which takes an Action as an argument, allowing the developer to either pass in drawing code or use a lambda expression:

C# Example

// Pre-iOS 10 drawing pattern
var size = new CGSize (100, 100);
UIGraphics.BeginImageContext (size);

// ... drawing statements here ...

UIGraphics.EndImageContext ();
image = UIGraphics.GetImageFromCurrentImageContext ();

// iOS 10 drawing model:

var r = new UIGraphicsImageRenderer(new CGSize(100, 100));

var img = r.CreateImage((UIGraphicsImageRendererContext ctxt) => 
    {
        var superRed = UIColor.FromDisplayP3(1.358f, -0.074f, -0.012f, 1.0f);
        superRed.SetFill();

        UIColor.Black.SetStroke();

        var path = new UIBezierPath();
        path.MoveTo(new CGPoint(10,10));
        path.AddLineTo(new CGPoint(90, 10));
        path.AddLineTo(new CGPoint(45, 90));
        path.ClosePath();
        path.Stroke();
        path.Fill();
    });

The new drawing method is still based on manipulating the state of a "current context" but instead of a CGContext it is now a subclass of UIGraphicsRendererContext (either UIGraphicsImageRendererContext or UIGraphicsPDFRendererContext). If necessary, developers can retrieve the current context as a CGContext using UIGraphicsRenderer.GetContext.

Related content

Requirements

Namespace: MonoTouch.UIKit
Assembly: monotouch (in monotouch.dll)
Assembly Versions: 0.0.0.0

The members of MonoTouch.UIKit.UIGraphicsImageRenderer are listed below.

See Also: UIGraphicsRenderer

Public Constructors

Default constructor, initializes a new instance of this class.
A constructor that initializes the object from the data stored in the unarchiver object.
Constructor to call on derived classes to skip initialization and merely allocate the object.
A constructor used when creating managed representations of unmanaged objects; Called by the runtime.

Public Properties

[read-only]
override
ClassHandleIntPtr. The handle for this class.

Public Methods