【发布时间】:2014-09-11 15:29:38
【问题描述】:
我正在尝试使用Path's FastImageCache library 来处理我的应用程序中的照片。他们提供的示例只是从磁盘读取图像。有谁知道我可以如何修改它以从 url 读取?在关于providing source images to the cache 的部分中,他们有
- (void)imageCache:(FICImageCache *)imageCache wantsSourceImageForEntity:(id<FICEntity>)entity withFormatName:(NSString *)formatName completionBlock:(FICImageRequestCompletionBlock)completionBlock {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Fetch the desired source image by making a network request
NSURL *requestURL = [entity sourceImageURLWithFormatName:formatName];
UIImage *sourceImage = [self _sourceImageForURL:requestURL];
dispatch_async(dispatch_get_main_queue(), ^{
completionBlock(sourceImage);
});
});
}
有没有人用过这个api并且知道如何从服务器获取源传递给缓存?另一个仍然使用硬盘的例子是
- (void)imageCache:(FICImageCache *)imageCache wantsSourceImageForEntity:(id<FICEntity>)entity withFormatName:(NSString *)formatName completionBlock:(FICImageRequestCompletionBlock)completionBlock {
// Images typically come from the Internet rather than from the app bundle directly, so this would be the place to fire off a network request to download the image.
// For the purposes of this demo app, we'll just access images stored locally on disk.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
UIImage *sourceImage = [(FICDPhoto *)entity sourceImage];
dispatch_async(dispatch_get_main_queue(), ^{
completionBlock(sourceImage);
});
});
}
【问题讨论】:
-
我建议使用 SDwebimage 或 AFN 来实现图像加载流畅和更快的捕获。
-
你找到解决办法了吗?
标签: ios objective-c caching uiimage