/** This file is part of the SDWebImage package.* (c) Olivier Poitrey <rs@dailymotion.com>** For the full copyright and license information, please view the LICENSE* file that was distributed with this source code.*/#import "ViewController.h"#import <SDWebImageWebPCoder/SDWebImageWebPCoder.h>#import <SDWebImage/SDWebImage.h>@interface ViewController ()@property (nonatomic, strong) UIImageView *imageView1;@property (nonatomic, strong) SDAnimatedImageView *imageView2;@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view, typically from a nib.[SDImageCache.sharedImageCache clearDiskOnCompletion:nil];[[SDImageCodersManager sharedManager] addCoder:[SDImageWebPCoder sharedCoder]];self.imageView1 = [UIImageView new];self.imageView1.contentMode = UIViewContentModeScaleAspectFit;[self.view addSubview:self.imageView1];self.imageView2 = [SDAnimatedImageView new];self.imageView2.contentMode = UIViewContentModeScaleAspectFit;[self.view addSubview:self.imageView2];NSURL *staticWebPURL = [NSURL URLWithString:@"https://www.gstatic.com/webp/gallery/2.webp"];NSURL *animatedWebPURL = [NSURL URLWithString:@"http://littlesvr.ca/apng/images/world-cup-2014-42.webp"];[self.imageView1 sd_setImageWithURL:staticWebPURL placeholderImage:nil options:0 context:@{SDWebImageContextImageThumbnailPixelSize : @(CGSizeMake(300, 300))} progress:nil completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {if (image) {NSLog(@"%@", @"Static WebP load success");}dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{NSUInteger maxFileSize = 4096;NSData *webpData = [SDImageWebPCoder.sharedCoder encodedDataWithImage:image format:SDImageFormatWebP options:@{SDImageCoderEncodeMaxFileSize : @(maxFileSize)}];if (webpData) {NSCAssert(webpData.length <= maxFileSize, @"WebP Encoding with max file size limit works");NSLog(@"%@", @"WebP encoding success");}});}];[self.imageView2 sd_setImageWithURL:animatedWebPURL placeholderImage:nil options:SDWebImageProgressiveLoad completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {if (image) {NSLog(@"%@", @"Animated WebP load success");}}];}- (void)viewWillLayoutSubviews {[super viewWillLayoutSubviews];self.imageView1.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height / 2);self.imageView2.frame = CGRectMake(0, self.view.bounds.size.height / 2, self.view.bounds.size.width, self.view.bounds.size.height / 2);}- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated.}@end
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。