改善iPhone4上的CoreGraphics性能

改善iPhone4上的CoreGraphics性能,iphone,Iphone,我正在合成两个(静态)图像,每秒几次。这段代码在3Gs上运行得很快,在iPhone4上运行得很慢。TimeProfiler揭示了对UIImage drawAtPoint:的调用最终调用了一个非常昂贵的东西,称为“argb_sample_RGBA21”。3Gs上从未调用此例程。是否有一些字节顺序转换,我可以对静态图像执行一次,从而保存这个字节顺序转换 + (UIImage * ) createInterpolatedImageBetween: (UIImage *) imageA

我正在合成两个(静态)图像,每秒几次。这段代码在3Gs上运行得很快,在iPhone4上运行得很慢。TimeProfiler揭示了对UIImage drawAtPoint:的调用最终调用了一个非常昂贵的东西,称为“argb_sample_RGBA21”。3Gs上从未调用此例程。是否有一些字节顺序转换,我可以对静态图像执行一次,从而保存这个字节顺序转换

+ (UIImage * ) createInterpolatedImageBetween: (UIImage *) imageA
                                     andImage:  (UIImage *) imageB
                                     forValue: (float) fractionalValue {

      UIGraphicsBeginImageContextWithOptions(CGSizeMake(imageA.size.width, imageA.size.height), YES, 0.0); 

      [imageA drawAtPoint: CGPointMake(0,0)];

      [imageB drawAtPoint: CGPointMake(0,0) 
                blendMode: kCGBlendModeNormal 
                    alpha: fractionalValue];


      UIImage *answer = UIGraphicsGetImageFromCurrentImageContext(); 
      UIGraphicsEndImageContext();
      return answer;

}核心图形本身速度较慢,因为它只在CPU上运行,不利用图形硬件。使用同一页面上的CICategoryCompositeOperation(可选)与CICategoryCompositeOperation组合使用将显著提高性能,但前提是您的目标是iOS 5或更高版本

这里有一个很好的核心形象介绍:

在iPhone4中,图像可以比3GS大很多,我认为这就是原因。确保正在处理所需大小的图像;)