How to optimise core-graphics manipulations into that method ?
I have profiled my app and it spends most of its time in this class method I wrote to combine two UIImages together:
+ (UIImage *)addImage:(UIImage *)image1 toImage:(UIImage *)image2 {开发者_运维问答
// Check if UIGraphicsBeginImageContextWithOptions is supported as this can create alphaless contexts and is faster
if (UIGraphicsBeginImageContextWithOptions != NULL) {
UIGraphicsBeginImageContextWithOptions(image1.size, YES, 0.0);
}
else{
UIGraphicsBeginImageContext(image1.size);
}
// Draw image1
[image1 drawInRect:CGRectMake(0, 0, image1.size.width, image1.size.height)];
// Draw image2
[image2 drawInRect:CGRectMake(0, 0, image2.size.width, image2.size.height)];
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultingImage;
}
Any gurus out there that can suggest ways of optimising this method? Or is it a case of running it in another thread and/or trying not to call it in the first place unless it is absolutely necessary?
When you say "most of its time", that's ambiguous of course, because it could include callees or not, and it could be CPU time or wall-clock time.
In any case, you want line-level information. What I do is just pause it a few times and examine the call stack. Statements that are responsible for significant time appear preferentially on the stack. If I want it to go faster, I need to find such a line of code that I can avoid executing.
精彩评论