除了它需要大约 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?
最佳答案
你可以:
- 获取 UIImages 的 CGImages
- 然后将它们绘制到 CGBitmapContext
- 从中生成图像
本身使用 CoreGraphics 可能会更快。另一个好处是您可以在后台线程上执行渲染。还要考虑如何使用 Instruments 优化该循环和配置文件。
其他注意事项:
- 可以降低插值质量吗?
- 是否以任何方式调整了源图像的大小(如果您调整它们的大小会有所帮助)
关于objective-c - UIImage drawInRect : is very slow; is there a faster way?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7911954/