CGImage/UIImage lazily loading on UI thread causes stutter

I’ve had the same stuttering problem, with some help I figured out the proper solution here: Non-lazy image loading in iOS

Two important things to mention:

  • Don’t use UIKit methods in a worker-thread. Use CoreGraphics instead.
  • Even if you have a background thread for loading and decompressing images, you’ll still have a little stutter if you use the wrong bitmask for your CGBitmapContext. This are the options you have to choose (it’s still a bit unclear to me why):

CGBitmapContextCreate(imageBuffer, width, height, 8, width*4, colourSpace,
                          kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little);

I’ve posted a sample project here: SwapTest, it has about the same performace as Apples’ Photos app for loading/displaying images.

Leave a Comment