【发布时间】:2016-02-26 19:06:27
【问题描述】:
UIImage *image = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:_actualImageURL.absoluteString];
if(!image) {
image = [UIImage imageNamed:@"placeholderImage"];
[self makeImageAvailableAtURL:_actualImageURL];
}
self.messageImage.image = [image isImageGif] ? image.images.lastObject : image;
我们正在从服务器加载图像。如果是 gif 图像,我们会得到带有.images 的图像(我无法理解它是不是 gif)。
- (BOOL)isImageGif {
return self.images;
}
但是如果我们用
存储 gif 图像 [[SDImageCache sharedImageCache] storeImage:image forKey:wImageURL.absoluteString];
,它失去了.images。
知道如何处理吗?
【问题讨论】:
-
好吧,我查过了。你想让我存储 NSData 而不是 UIImage 左右?了解 gif 与否,我已经有了(但很脏)。
-
NSData *imageData = UIImagePNGRepresentation(myImage.image);您必须将其转换为 nsdata 。 P.S 您还可以从文件创建 nsdat 并为其提供 url。 developer.apple.com/library/mac/documentation/Cocoa/Reference/…
-
好的,让我们从图像创建 NSData。它会保存gif吗?它会不知不觉地转换为 png/jpeg。无论如何都需要以某种方式缓存 NSData。
-
是的,你是对的。如果您直接从 Web 服务提供的 NSData 上查询它会很好。我想您必须保存 nsdata 并在需要图像时将其转换为图像。
标签: ios image animated-gif sdwebimage