What I’m doing is merge 2 images into single image.
Here is the code.
UIGraphicsBeginImageContext(CGSizeMake(1024, 768));
[image1 drawInRect:CGRectMake(0, 0, 512, 768)];
[image2 drawInRect:CGRectMake(512, 0, 512, 768)];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
But drawInRect seems too slow.
Is there faster way to merge images?
Option 0 – Make sure you draw only when you need to draw, and only what you need to draw.
Option 1
If you know the destination size (perhaps
self.frame.size?), you can create one image from the two source images (flatten) at the destination size and avoid interpolation. So that could:Of course, this only makes sense when the composite varies at a frequency lower than it must be drawn.
Option 2
Even if you want two images and you know their sizes will not change, just resize them to the size they must be drawn at (well, monitor your memory usage if you are enlarging them).
Option 3
If that’s not an option, you could alter the
CGContext‘s state, and reduce interpolation quality. If you’re used to similar CALayer transformations, you would probably be satisfied with low quality or no interpolation.