// // UIImage+PHAsset.m // QSport // // Created by ko1o on 2018/12/7. // Copyright © 2018年 ko1o. All rights reserved. // #import "UIImage+PHAsset.h" #import #import "FLAnimatedImage.h" @implementation UIImage (PHAsset) + (void)getImageDataFromAsset:(PHAsset *)asset completion:(void (^)(NSData * _Nonnull, NSString * _Nonnull))completion { PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init]; options.deliveryMode = PHImageRequestOptionsDeliveryModeFastFormat; [PHImageManager.defaultManager requestImageDataForAsset:asset options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) { if(completion) { completion(imageData,[info[@"PHImageFileURLKey"] lastPathComponent]); } }]; } + (id)getImageWithContentFile:(NSString *)file { NSString *subfix = [file lowercaseString].lastPathComponent; NSData *data = [NSData dataWithContentsOfFile:file]; id image = nil; if ([subfix isEqualToString:@"gif"]) { // GIF image = [FLAnimatedImage animatedImageWithGIFData:data]; } else { image = [UIImage imageWithData:data]; } return image; } @end