Christer Nordvik
Christer Nordvik

Reputation: 2528

Capture iPhoneOSGameView as an Image

I am writing a signaturecontroller where the user would write his signature and then I take the signature as an image and save post it back to the server.

I quickly found this excellent sample: https://github.com/xamarin/monotouch-samples/blob/master/GLPaint-GameView/PaintingView.cs

But I am having trouble saving the result of the painting as an image. The code below just provides a black picture without the actual drawings so how do I paint the result of the drawing to the image context?

PaintingView drawingView;

...

UIGraphics.BeginImageContext(drawingView.Frame.Size); 
var ctx = UIGraphics.GetCurrentContext();
drawingView.Layer.RenderInContext(ctx);
UIImage img = UIGraphics.GetImageFromCurrentImageContext();                         
UIGraphics.EndImageContext();

Upvotes: 2

Views: 233

Answers (2)

Herman Schoenfeld
Herman Schoenfeld

Reputation: 8724

MonoTouch provides screen capture convenience methods to capture the contents of the screen while running with UIKit or OpenGL.

UIKit applications

    var screenshot = UIScreen.MainScreen.Capture ();

GLKit applications

    var screenshot = iPhoneOSGameView.Capture ();

Upvotes: 1

poupou
poupou

Reputation: 43543

When using OpenGL capturing a screenshot can be done by following Apple instructions in this technical note.

Normal (non OpenGL) captures can be done following this note.

Upvotes: 2

Related Questions