核心显卡优化

发布于 2024-10-07 16:16:32 字数 1483 浏览 2 评论 0原文

我的这段代码在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

明月松间行 2024-10-14 16:16:32

您应该在 -drawRect: 中为您的视图进行绘图,而不是直接响应触摸。

You should do your drawing in -drawRect: for your view instead of directly in response to a touch.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文