Created
January 11, 2016 13:03
-
-
Save EmingK/967f8d3f241187a022ed to your computer and use it in GitHub Desktop.
Test image rendering with kCAFilterTrilinear on iPhone 5C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ImageLoadVC.h | |
// touchtest | |
@import UIKit; | |
@interface ImageLoadVC : UIViewController | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ImageLoadVC.m | |
// touchtest | |
#import "ImageLoadVC.h" | |
@import Photos; | |
@interface ImageLoadVC () | |
@property (nonatomic, strong) NSMutableArray<UIImageView *> *imageViews; | |
@property (nonatomic, strong) UIScrollView *scrollView; | |
@end | |
@implementation ImageLoadVC | |
- (void)viewDidLoad { | |
_imageViews = [NSMutableArray array]; | |
_scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds]; | |
_scrollView.contentSize = (CGSize){ .width = self.view.bounds.size.width, .height = 550 }; | |
[self.view addSubview:_scrollView]; | |
// create a series of image views in different size. | |
CGFloat lastTop = 0; | |
for (int i=0; i < 10; ++i) { | |
CGFloat h = (i+1)*10; | |
UIImageView *imageView = [[UIImageView alloc] initWithFrame:(CGRect){.origin = {0, lastTop}, .size = {h,h}}]; | |
// applying these filters cause images not displayed properly on some resolution. | |
imageView.layer.magnificationFilter = kCAFilterTrilinear; | |
imageView.layer.minificationFilter = kCAFilterTrilinear; | |
[_scrollView addSubview:imageView]; | |
[_imageViews addObject:imageView]; | |
lastTop += h; | |
} | |
[self loadPhoto]; | |
} | |
- (void)loadPhoto { | |
// get a photo from the album. | |
PHFetchResult<PHAsset *> *fetchResult = [PHAsset fetchAssetsWithOptions:nil]; | |
PHAsset *asset = [fetchResult lastObject]; | |
NSLog(@"image id is %@", asset.localIdentifier); | |
PHImageRequestOptions *fetchOptions = [PHImageRequestOptions new]; | |
fetchOptions.resizeMode = PHImageRequestOptionsResizeModeFast; | |
fetchOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat; | |
for (int i=0; i<10; ++i) { | |
CGFloat h = (i+1)*10; | |
CGSize targetSize = {h,h}; | |
// repeat requesting image each time to see effects on different source images. | |
[[PHImageManager defaultManager] requestImageForAsset:asset targetSize:targetSize contentMode:PHImageContentModeAspectFill options:fetchOptions resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) { | |
NSLog(@"image size is %@, targetSize is %@", NSStringFromCGSize(result.size), NSStringFromCGSize(targetSize)); | |
_imageViews[i].image = result; | |
}]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment