核心显卡优化
我的这段代码在 iPad 上运行速度非常慢(由于某种原因在 iPhone 上运行速度快得多):
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[self.navigationController setNavigationBarHidden:YES animated:NO];
mouseSwiped = YES;
UITouch *touch = [touches anyObject];
currentPoint = [touch locationInView:frontgroundView];
CGContextBeginPath(context);
CGContextMoveToPoint(context, lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(context, currentPoint.x, currentPoint.y);
CGContextStrokePath(context);
maskRef = CGBitmapContextCreateImage(context);
CGImageRef masked = CGImageCreateWithMask([backgroundImage CGImage], maskRef);
CGImageRelease(maskRef);
CGContextRef drawContext = UIGraphicsGetCurrentContext();
CGContextSaveGState(drawContext);
CGContextTranslateCTM (drawContext,0,frontgroundView.frame.size.height);
CGContextScaleCTM (drawContext, 1,-1);
CGContextDrawImage(drawContext, CGRectMake(0, 0, frontgroundView.frame.size.width, frontgroundView.frame.size.height), [frontgroundView.image CGImage]);
CGContextRestoreGState (drawContext);
CGContextDrawImage(drawContext, CGRectMake(0, 0, frontgroundView.frame.size.width, frontgroundView.frame.size.height), masked);
CGImageRef finalImage = CGBitmapContextCreateImage(drawContext);
frontgroundView.image = [UIImage imageWithCGImage:finalImage];
CGImageRelease(finalImage);
CGImageRelease(masked);
lastPoint = currentPoint;
mouseMoved++;
if (mouseMoved == 10)
mouseMoved = 0;
}
有什么想法吗?
I have this code that's running really slowly on the iPad (for some reason much faster on the iPhone):
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[self.navigationController setNavigationBarHidden:YES animated:NO];
mouseSwiped = YES;
UITouch *touch = [touches anyObject];
currentPoint = [touch locationInView:frontgroundView];
CGContextBeginPath(context);
CGContextMoveToPoint(context, lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(context, currentPoint.x, currentPoint.y);
CGContextStrokePath(context);
maskRef = CGBitmapContextCreateImage(context);
CGImageRef masked = CGImageCreateWithMask([backgroundImage CGImage], maskRef);
CGImageRelease(maskRef);
CGContextRef drawContext = UIGraphicsGetCurrentContext();
CGContextSaveGState(drawContext);
CGContextTranslateCTM (drawContext,0,frontgroundView.frame.size.height);
CGContextScaleCTM (drawContext, 1,-1);
CGContextDrawImage(drawContext, CGRectMake(0, 0, frontgroundView.frame.size.width, frontgroundView.frame.size.height), [frontgroundView.image CGImage]);
CGContextRestoreGState (drawContext);
CGContextDrawImage(drawContext, CGRectMake(0, 0, frontgroundView.frame.size.width, frontgroundView.frame.size.height), masked);
CGImageRef finalImage = CGBitmapContextCreateImage(drawContext);
frontgroundView.image = [UIImage imageWithCGImage:finalImage];
CGImageRelease(finalImage);
CGImageRelease(masked);
lastPoint = currentPoint;
mouseMoved++;
if (mouseMoved == 10)
mouseMoved = 0;
}
Any ideas??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该在 -drawRect: 中为您的视图进行绘图,而不是直接响应触摸。
You should do your drawing in -drawRect: for your view instead of directly in response to a touch.