0
 UIGraphicsBeginImageContext(self.view.bounds.size);
        [currentStrokeImageView.image drawInRect:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
        CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
        CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeNormal);
        CGContextSetLineWidth(UIGraphicsGetCurrentContext(), dWidth);
        CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), r, g, b, 1.0f);
        CGContextBeginPath(UIGraphicsGetCurrentContext());
        CGContextMoveToPoint(UIGraphicsGetCurrentContext(), pointA.x, pointA.y);
        CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), pointB.x, pointB.y);
        CGContextStrokePath(UIGraphicsGetCurrentContext());
        currentStrokeImageView.image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();

For some reason this runs with absolutely no lag on the iphone/ipod but on the iPad their is a significant lag while drawing. The code I use is above, any suggestions to fix this?

pnuts
  • 58,317
  • 11
  • 87
  • 139
Aspyn
  • 647
  • 1
  • 10
  • 25

1 Answers1

3

The reason why this is so laggy is because you are doing it in the touchesMoved:withEvent:. This method can be called many, many times (obviously) while touch events are received. Because drawing to a graphics context can be a resource intensive operation, I would recommend not doing all the things you are doing there. I would, as much as possible, defer the rendering you are doing to the touchesBegin and touchesEnd methods. If that is not possible, perhaps you could only preform these operations once a certain delta has been reached in the movements, for example, every 2.0f points.

Wayne Hartman
  • 18,369
  • 7
  • 84
  • 116
  • I have tried both the delta method (using distance formula) and the timer method of trying to get this to work. The problem with the delta method is that the touches moved is always at least one, so for precise drawing the delta method doesn't change anything. With the timer method it doesn't update enough times and fast enough to keep up with the touches (even 250.0f/1.0f, 300.0f/1.0f). So do you know any other solution. Thanks for the first two but if you know of another please reply – Aspyn Oct 01 '11 at 14:40