I am drawing pieces of a CGBitmapContext in the drawRect of a UIView. What are the best CGBitmapInfo enum values to ensure that performance is optimal? Right now I am using kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big, but I have also seen this stackoverflow question snippet which suggests an alternative:
Why does this code decompress a UIImage so much better than the naive approach?
// makes system don't need to do extra conversion when displayed.
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little
My CGBitmapContext is mutable, so the user can draw on it, add images to it, etc.
I ran tests with
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32BigvskCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Littleand the profiler did show me that there is a slightly different code path.kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Littlecopies memory directly, whilekCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Biggoes through a conversion function.This made almost no impact in the total time it took to draw paths in my
CGBitmapContext(even on an iPod 4) and then callsetNeedsDisplayInRect:to show them on screen. Furthermore since the overall times are essentially identical, I'm sticking withkCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big.EDIT I switched back to
kCGBitmapByteOrder32Littlein order to have better compatibility with other iOS frameworks (like AVFoundation) that use BGRA (little endian) byte orders since there was no impact on performance.