简体   繁体   中英

Loading 8MP photos in the background on iOS

I'm customizing a gallery similar to the Photos app in iOS. I want to be able to scroll between individual photos in my custom gallery. I am also preloading images that are likely to be shown soon (if I scroll to the right, I preload ie the 2 next images to the right)

However, the image loading seems to be so CPU consuming that it interferes with the scrolling. Making the scrolling hang for split of a second.

Is there any better way to do this? (I have considered keeping smaller versions of each image that matches the screen resolution)

Basically I call this in the background thread:

UIImage *img = [UIImage imageWithContentsOfFile:path];

and then I perform a selector on the main thread that just initialises an existing ImageView with the loaded image.

I figured it out in a way.

I needed to render the image off-screen on the background thread to make sure it was loaded. Otherwise it would not actually load until I decided to render it in the main thread. This caused the main thread to block while loading.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM