我正在使用SDWebImage在iOS应用程序中加载图像,现在我想使用webp格式。
这是我的第一次尝试:
NSURL *url = [NSURL URLWithString:@"http://www.gstatic.com/webp/gallery/2.webp"];
[self.imageView setImageWithURL:url
placeholderImage:nil
options:SDWebImageProgressiveDownload
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
if (error) {
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[av show];
}
}];
如果图像是jpeg(我尝试过),它将完美地工作,但是使用webp则不是。我第一次调用此代码时,错误是:
Downloaded image has 0 pixels
然后错误变为:
The operation couldn't be completed. (NSURLErrorDomain error -1100.)
怎么了?
实际上,上面的代码应该可以工作,但是默认情况下在库中禁用了webp支持。
添加SD_WEBP=1
sdwebimage目标的预处理器宏(在构建设置中)将启用webp支持
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句