简体   繁体   English

在iOS上后台加载8MP照片

[英]Loading 8MP photos in the background on iOS

I'm customizing a gallery similar to the Photos app in iOS. 我正在自定义类似于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) 我还预加载了可能很快就会显示的图像(如果向右滚动,则预加载即右边的2张下一张图像)

However, the image loading seems to be so CPU consuming that it interferes with the scrolling. 但是,图像加载似乎非常消耗CPU,以至于干扰了滚动。 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. 然后在主线程上执行选择器,该选择器仅使用加载的图像初始化现有的ImageView。

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. 这导致主线程在加载时阻塞。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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