iphone - 合并两个图像花费太多时间

标签 iphone ios ios5 ios4

我正在开发我想合并图像的应用程序,但是当我迭代调用该函数时,它花费了太多时间。任何人请告诉我如何改进该函数的响应。

- (UIImage *) addImageToImage:(UIImage *)img withImage2:(UIImage *)img2 andRect:(CGRect)cropRect withImageWidth:(int) width
{
CGSize size = CGSizeMake(width,40);
UIGraphicsBeginImageContext(size);

CGPoint pointImg1 = CGPointMake(0,0);
[img drawAtPoint:pointImg1];

CGPoint pointImg2 = cropRect.origin;
[img2 drawAtPoint: pointImg2];

UIImage* result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return result;
}

这个函数在迭代中被调用了 30 到 50 次...所以我需要提高它的效率。

最佳答案

一些想法:

  1. 缓存结果(如果使用相同参数重复使用图像)
  2. 同时执行合并
  3. 重用上下文(使用 CGBitmapContextCreate 而不是 UIGraphicsBeginImageContext 创建上下文)
  4. 将插值质量设置为较小的值:CGContextSetInterpolationQuality(context, kCGInterpolationNone)

还有一些潜在的优化,但它们取决于图像的类型(alpha、大小、类型……)。

关于iphone - 合并两个图像花费太多时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18187201/

相关文章:

iphone - UIActionSheet 按钮颜色问题

iphone - iOS 5 在它被解雇之前持有一个方法一段时间

ios - 我应该为这个完整的场景使用操作队列吗?

iphone - UITableViewCell 中的多种颜色

iphone - Objective-C:AutoresizingMask + 2 Subviews = 挣扎

iphone - 记住swift中2个ViewController的高分

iphone - 基础 SDK 缺失错误

javascript - react native : How to keep multi-line textinput visible above keyboard

ios - 当我尝试在我的设备中启动我的应用程序时,我在我的 xcode 中收到作为启动选项 nil 的错误?

ios - -[非类型保留] : message sent to deallocated instance