In this recipe, we will expand the finger drawing application that we created previously by providing the user with the feature of saving the created drawings.
Create a new project in MonoDevelop, and name it ImageContextApp
. Add the CanvasView
class that we created in the previous task to the project.
Add two buttons on the view of
MainController
. One will be used for saving the image and the other for clearing the current drawing.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.GetImageFromCurrentImageContext...