UIImage drawInRect:很慢;有没有更快的方法? [英] UIImage drawInRect: is very slow; is there a faster way?

查看:36
本文介绍了UIImage drawInRect:很慢;有没有更快的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这正是它需要做的,除了它需要大约 400 毫秒,350 毫秒太多了:

This does exactly what it needs to, except that it takes about 400 milliseconds, which is 350 milliseconds too much:

 - (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循环只迭代两次)

The images are fairly small, and there are only three of them (the for loop only iterates twice)

有没有办法更快地做到这一点?虽然仍然可以使用 kCGBlendModeScreen 和 alpha?

Is there any way of doing this faster? While still being able to use kCGBlendModeScreen and alpha?

推荐答案

您可以:

  • 获取 UIImages 的 CGImages
  • 然后将它们绘制到 CGBitmapContext
  • 从中生成图像

单独使用 CoreGraphics 可能会更快.另一个好处是您可以在后台线程上执行渲染.还要考虑如何使用 Instruments 优化该循环和配置文件.

using CoreGraphics in itself may be faster. the other bonus is that you can perform the rendering on a background thread. also consider how you can optimize that loop and profile using Instruments.

其他注意事项:

  • 你能降低插值质量吗?
  • 是否以任何方式调整了源图像的大小(如果调整它们的大小会有所帮助)

这篇关于UIImage drawInRect:很慢;有没有更快的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆