Book Image

iOS Development with Xamarin Cookbook

By : Dimitrios Tavlikos (USD)
Book Image

iOS Development with Xamarin Cookbook

By: Dimitrios Tavlikos (USD)

Overview of this book

Table of Contents (22 chapters)
iOS Development with Xamarin Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating an image context


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.

Getting ready

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.

How to do it...

Perform the following steps:

  1. 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...