This could very well be problems with the limited amount of memory on the iPhone, as you create a new ImageContext every time you have a touch event it probably does not dispose of the old items fast enough, flooding the memory quickly and running low.
A better approach could be to draw on a layer and save that onto the image when done with all the annotations, instead of drawing directly to the image. On Thu, Feb 2, 2012 at 11:52 AM, Richard <[email protected]> wrote: > Hello, > > i am using drawontouch to make some annotations on a picture. > when i make short movements (drawing small lines for instance by making > short contact with the screen) it all works fine. But when i want to make a > long line and move across the screen > my app just crashes. > > anyone know what this could be? > > > private void drawOnTouch(object data) > { > > UITouch touch = data as UITouch; > > if (null != touch) > { > > UIGraphics.BeginImageContext(this.Image == null ? this.Frame.Size : > this.Image.Size); > > using (CGContext cont = UIGraphics.GetCurrentContext()) > { > > if (this.Image != null) > { > > cont.TranslateCTM(0f, this.Image.Size.Height); > cont.ScaleCTM(1.0f, -1.0f); > cont.DrawImage(new RectangleF(0f,0f,this.Image.Size.Width, > this.Image.Size.Height), this.Image.CGImage); > cont.ScaleCTM(1.0f, -1.0f); > cont.TranslateCTM(0f, -this.Image.Size.Height); > > > } //end if > > PointF lastLocation = touch.PreviousLocationInView(this); > PointF pt = touch.LocationInView(this); > using (CGPath path = new CGPath()) > { > > cont.SetLineCap(CGLineCap.Round); > cont.SetLineWidth(3); > cont.SetRGBStrokeColor(0, 2, 3, 1); > path.MoveToPoint(lastLocation.X, lastLocation.Y); > path.AddLines(new PointF[] { new PointF(lastLocation.X, > lastLocation.Y), > new PointF(pt.X, pt.Y) }); > path.CloseSubpath(); > > cont.AddPath(path); > cont.DrawPath(CGPathDrawingMode.FillStroke); > this.Image = UIGraphics.GetImageFromCurrentImageContext(); > > }//end using path > > > }//end using cont > UIGraphics.EndImageContext(); > this.SetNeedsDisplay(); > > }//end if > > > }//end void drawOnTouch > > -- > View this message in context: > http://monotouch.2284126.n4.nabble.com/drawontouch-tp4351088p4351088.html > Sent from the MonoTouch mailing list archive at Nabble.com. > _______________________________________________ > MonoTouch mailing list > [email protected] > http://lists.ximian.com/mailman/listinfo/monotouch -- Med Venlig Hilsen / With Best Regards Tomasz Cielecki http://ostebaronen.dk _______________________________________________ MonoTouch mailing list [email protected] http://lists.ximian.com/mailman/listinfo/monotouch
