In this recipe, we will extend the finger-drawing app we created earlier by providing a save functionality for the drawings that the user will create.
Create a new Single View Application in Xamarin Studio and name it ImageContextApp
. Add the CanvasView
class we created in the earlier task to the project. Don't forget to change the namespace in the CanvasView.cs
file to correspond to the namespace of the new project.
Perform the following steps:
Add the following methods in the
CanvasView
class:public UIImage GetDrawingImage() { UIImage toReturn = null; UIGraphics.BeginImageContext(this.Bounds.Size); using (CGContext context = UIGraphics.GetCurrentContext()) { context.SetStrokeColorWithColor(UIColor.Blue.CGColor); context.SetLineWidth(10f); context.SetLineJoin(CGLineJoin.Round); context.SetLineCap(CGLineCap.Round); context.AddPath(this.drawPath); context.DrawPath(CGPathDrawingMode.Stroke); toReturn = UIGraphics...