0

I am writing an app that takes a picture using the iDevice camera and stores it on the file system as a PNG. When starting my app, I load a UICollectionView with the images found on the file system.

The issue I am facing is that the load time for the app (even when its only loading 6 images is approximately 4 seconds which is unacceptable. I have implemented GCD to load images on a background thread (which keeps the UI snappy) however I really want the app to start far quicker with images loaded.

My thoughts are:

I suspect the initWithContentsOfFile is taking ages to load the full size image. I thought about generating a separate thumbnail image when a picture is taken and load that instead.

Ultimately when I look at Apple's Photo app, it loads "instantly" and has 10's of pictures in view.

Does anyone have any suggestions for how I can load the images faster or at least appear to?

Thanks!

Spanners
  • 366
  • 2
  • 20

2 Answers2

0

Try this

Load image in background thread and set in main thread

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{

    UIImage *image = [UIImage imageWithContentsOfFile:frontPath];

    dispatch_async(dispatch_get_main_queue(), ^{
        [self.frontButton setBackgroundImage:image forState:UIControlStateNormal];
    });
});
iYoung
  • 3,596
  • 3
  • 32
  • 59
abhishekkharwar
  • 3,529
  • 2
  • 18
  • 31
0

Check this sample code and try to get some idea from it https://developer.apple.com/library/ios/samplecode/lazytableimages/introduction/intro.html

Sandeep Ahuja
  • 931
  • 6
  • 17
  • Read that this morning and I don't see which bit helps? Am I missing something? I understand I can put a placeholder image whilst the cells load, however that isn't what the Photo app does. – Spanners Mar 25 '14 at 10:23
  • @Spanners: see this project helps to download images from network and in your case images data is stored on your local db, so try to take idea from this.. Hope this helps you, otherwise refer to some lazy image loading tutorials on web might helps you. – Sandeep Ahuja Mar 25 '14 at 11:30