-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathViewController.m
61 lines (47 loc) · 2.48 KB
/
ViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// ViewController.m
// SDWebImageAVIFCoder_Example macOS
//
// Created by lizhuoli on 2019/4/14.
// Copyright © 2019 lizhuoli1126@126.com. All rights reserved.
//
#import "ViewController.h"
#import <SDWebImage/SDWebImage.h>
#import <SDWebImageAVIFCoder/SDImageAVIFCoder.h>
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
SDImageAVIFCoder *AVIFCoder = [SDImageAVIFCoder sharedCoder];
[[SDImageCodersManager sharedManager] addCoder:AVIFCoder];
NSURL *AVIFURL = [NSURL URLWithString:@"https://raw.githubusercontent.com/link-u/avif-sample-images/master/fox.profile0.8bpc.yuv420.avif"];
// NSURL *HDRAVIFURL = [NSURL URLWithString:@"https://raw.githubusercontent.com/link-u/avif-sample-images/master/hato.profile2.12bpc.yuv422.avif"];
NSURL *animatedAVIFSURL = [NSURL URLWithString:@"https://raw.githubusercontent.com/link-u/avif-sample-images/master/star-12bpc-with-alpha.avifs"];
CGSize screenSize = self.view.bounds.size;
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, screenSize.width / 2, screenSize.height)];
imageView1.imageScaling = NSImageScaleProportionallyUpOrDown;
SDAnimatedImageView *imageView2 = [[SDAnimatedImageView alloc] initWithFrame:CGRectMake(screenSize.width / 2, 0, screenSize.width / 2, screenSize.height)];
imageView2.imageScaling = NSImageScaleProportionallyUpOrDown;
[self.view addSubview:imageView1];
[self.view addSubview:imageView2];
[imageView1 sd_setImageWithURL:AVIFURL completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
if (image) {
NSLog(@"Static AVIF load success");
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData *avifData = [SDImageAVIFCoder.sharedCoder encodedDataWithImage:image format:SDImageFormatAVIF options:nil];
if (avifData) {
NSLog(@"Static AVIF encode success");
}
});
}
}];
[imageView2 sd_setImageWithURL:animatedAVIFSURL completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
if (image) {
NSLog(@"Animated AVIFS load success");
}
}];
}
- (void)setRepresentedObject:(id)representedObject {
[super setRepresentedObject:representedObject];
// Update the view, if already loaded.
}
@end