objective-c - UIImage drawInRect : is very slow; is there a faster way?

标签 objective-c ios image uiimage drawing

除了它需要大约 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/

相关文章:

ios - 当应用程序在 iOS 中关闭且应用程序未在后台运行时从推送通知获取数据

ios - 将NSString附加到NSArray时仅获取一个值

java - 托盘图标的最佳图像格式

image - Firefox - 设计模式 : disable image resizing handles

ios - 多次将UIImage压缩成JPEG图片数据

objective-c - 当前 View Controller 显示黑屏

objective-c - iOS 初学者 : UIAlertView Window with 3 Buttons > Check what button was pressed

ios - 无法在 iOS 8 上选择联系人

objective-c - Objective-C中的id类型真的是动态的吗

javascript - 覆盖 &lt;input type ="file"> value 属性