如何使用资源库加快图像加载速度?
我正在编写一个应用程序,它是 UIImagePicker 的克隆,但使用 Assets 库。当用户选择照片时,加载图像的时间有点太长。我注意到,当我使用与我正在开发的功能相同的照片应用程序时,图像加载速度要快一些。我听到该网站上的另一位响应者提到以下内容,以模仿照片应用程序的功能:
“首先加载缩略图(最好使用dispatch_async) - 这应该非常快。完成后,加载全屏图像就像你上面所做的那样,这就是苹果在照片应用程序中所做的,以提供流畅的用户体验。”
有人有如何实现这一点的代码示例吗?我不太确定我是否明白他的意思。
这也是我用来加载图像的代码(我将图像作为参数传递给另一个视图控制器):
myImage = [UIImage imageWithCGImage:[[myAsset defaultRepresentation] fullScreenImage]];
I am writing an app that is a clone of the UIImagePicker but uses the Assets library. When the user selects a photo, it takes a little bit too long for the image to load. I notice that when I use the photos app which has identical functionality as to what I'm developing, that the image loading is a bit faster. I've heard another responder on this site mention the following in order to mimic the functionality of the photos app:
"Load the thumbnail image first (best with dispatch_async) - that should be really quick. When this has completed, load the fullscreen image like you did above. This is what apple does in the Photo App to provide a smooth user experience."
Does anyone have any code samples of how this can be accomplished? I'm not quite sure that I understand what he means.
Also here is my code for which I'm using to load an image (I'm passing the image as a parameter to another view controller):
myImage = [UIImage imageWithCGImage:[[myAsset defaultRepresentation] fullScreenImage]];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ALAsset
类有两种获取缩略图的方法:我敢打赌它们比获取资源的全屏大小版本更快。
此外,您还可以使用异步操作来包装它们。请务必在主线程中更新 UI。大致如下:
如果您需要获取视频的缩略图,您应该使用
AVAssetImageGenerator
。它有一个异步获取它们的方法。查找 Apple 示例代码(AVEditDemo 以及可能使用资产库的其他代码)。
The class
ALAsset
has two methods to obtain thumbnails:I bet they are faster than obtaining the full screen sized version of the asset.
Also, you can wrap them with an async operation. Be sure to update the UI in main thread. Roughly like this:
If you need to obtain thumbnails for videos you should use
AVAssetImageGenerator
. It has a method to obtain them asynchronously.Look for Apple sample code (AVEditDemo and probably others working with assets library).