【问题标题】:ios fast Image cache with serverios快速图像缓存与服务器
【发布时间】: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


【解决方案1】:

我在 Path 时从事快速图像缓存的工作。 Fast Image Cache 的关键部分是它是从磁盘上的图像数据到由 Core Animation 渲染的绝对最快的方式。不会发生解码,您的应用不会将任何图像数据保存在内存中,也不会发生图像副本。

也就是说,您有责任弄清楚如何下载图像。下载图像本身并没有什么特别之处。您可以使用NSURLConnection 或许多流行的网络库之一(如 AFNetworking)从您的服务器实际下载图像数据。获得该图像数据后,您可以调用 Fast Image Cache 的相关完成块,以使其优化以供将来渲染。

如果您正在寻找一种简单的方法来下载图像并在完成后显示它,那么请使用 SDWebImage 之类的东西。这对于像这样的简单情况非常有用。如果由于您的应用需要快速显示大量图像而遇到性能瓶颈(尤其是在滚动时),那么 Fast Image Cache 非常适合您。

【讨论】:

    【解决方案2】:

    您的方法似乎很像从 URL 延迟加载图像,一旦我使用了以下库来执行此操作,我就必须这样做,它将图像存储在磁盘中,但使用缓存的图像..下面是它的链接.. https://github.com/nicklockwood/AsyncImageView

    【讨论】:

      【解决方案3】:

      我将网络逻辑添加到我们的 fork > https://github.com/DZNS/FastImageCache#dezine-zync-additions-to-the-class

      它利用 NSURLSessionDownloadTasks,有几个配置选项(可选)。您需要做的就是创建一个DZFICNetworkController 的新实例并将其设置为FICImageCache 的sharedCache 实例对象的委托。它会参考sourceImageURLWithFormatName: 方法在符合&lt;FICEntity&gt; 的对象上下载图像。

      我假设您会在UITableViewUICollectionView 中使用它,在imageCache 上调用cancelImageRetrievalForEntity:withFormatName: 将取消下载操作(如果它仍在进行中或尚未开始)。

      【讨论】:

        猜你喜欢
        • 2019-06-19
        • 2014-05-12
        • 1970-01-01
        • 2023-04-08
        • 1970-01-01
        • 2023-03-31
        • 2019-09-14
        • 1970-01-01
        相关资源
        最近更新 更多