title: Xamarin iOS - Drawing onto image after scaling it
body: <p>I have an app where the user can draw freely on a loaded image. He chooses a pencil color, and start drawing onto the image.</p>
  
  <p>Along with that, he can scale the image down and up, using the fingers, that's where i'm having problems.</p>
  
  <p><strong>After scaling, when drawing onto the image, it gets blurry, and strangely shrinks..</strong></p>
  
  <p><strong>Code for scaling:</strong></p>
  
  <pre><code>void ScaleImage (UIPinchGestureRecognizer gestureRecognizer)
          {
              AdjustAnchorPoint (gestureRecognizer);
              if (gestureRecognizer.State == UIGestureRecognizerState.Began || gestureRecognizer.State == UIGestureRecognizerState.Changed) {
                  gestureRecognizer.View.Transform *= CGAffineTransform.MakeScale (gestureRecognizer.Scale, gestureRecognizer.Scale);
                  gestureRecognizer.Scale = 1;
              }
          }
  </code></pre>
  
  <p><strong>Code for drawing:</strong></p>
  
  <pre><code>public override void TouchesBegan (NSSet touches, UIEvent evt)
              {
                  base.TouchesBegan (touches, evt);
  
                  if (!canDraw)
                      return;
  
                  UITouch touch = (UITouch)touches.AnyObject;
                  lastPoint = touch.LocationInView (MyImageView);
              }
  
  public override void TouchesMoved (NSSet touches, UIEvent evt)
          {
              base.TouchesMoved (touches, evt);
  
              if (!canDraw)
                  return;
  
              UITouch touch       = (UITouch)touches.AnyObject;
              PointF currentPoint = touch.LocationInView (MyImageView);
  
              UIGraphics.BeginImageContext (MyImageView.Frame.Size);
  
              MyImageView.Image.Draw (new RectangleF (
                  0, 0,
                  MyImageView.Frame.Size.Width,
                  MyImageView.Frame.Size.Height));
  
              CGContext ctx = UIGraphics.GetCurrentContext ();
              ctx.SetLineCap (CGLineCap.Round);
              ctx.SetLineWidth (5.0f);
              ctx.SetRGBStrokeColor (red, green, blue, 1);
  
              CGPath path = new CGPath ();
              path.MoveToPoint(MyImageView.Transform, lastPoint.X, lastPoint.Y);
              path.AddLineToPoint (MyImageView.Transform, currentPoint.X, currentPoint.Y);
              ctx.AddPath (path);
              ctx.DrawPath (CGPathDrawingMode.Stroke);
  
              MyImageView.Image = UIGraphics.GetImageFromCurrentImageContext ();
              UIGraphics.EndImageContext ();
  
              lastPoint = currentPoint;
          }
  </code></pre>
  
  <p>Thanks in advance!</p>