[英]stretchableImageWithLeftCap: --> drawInRect -->very slow?
[英]UIImage drawInRect: is very slow; is there a faster way?
这正是它所需要的,除了它需要大约400毫秒,这是350毫秒太多:
- (void) updateCompositeImage { //blends together the background and the sprites
UIGraphicsBeginImageContext(CGSizeMake(480, 320));
[bgImageView.image drawInRect:CGRectMake(0, 0, 480, 320)];
for (int i=0;i<numSprites;i++) {
[spriteImage[spriteType[i]] drawInRect:spriteRect[i] blendMode:kCGBlendModeScreen alpha:spriteAlpha[i]];
}
compositeImageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
图像相当小,只有三个(for循环只迭代两次)
有没有办法更快地做到这一点? 虽然仍然可以使用kCGBlendModeScreen和alpha?
您可以:
使用CoreGraphics本身可能会更快。 另一个好处是你可以在后台线程上执行渲染。 还要考虑如何使用Instruments优化该循环和配置文件。
其他考虑:
drawInRect很慢。 期。 即使在小图像中,它也是非常低效的。
如果你正在做很多重复绘图,那么看看CGLayer,它旨在促进相同位的重复渲染
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.