美文网首页iOS
iOS 将相册中的动态GIF图转化为NSData类型

iOS 将相册中的动态GIF图转化为NSData类型

作者: 彗星来的那一夜 | 来源:发表于2017-04-26 17:09 被阅读14次

NSURL *imageRefURL = [info valueForKey:UIImagePickerControllerReferenceURL];

ALAssetsLibrary* assetLibrary = [[ALAssetsLibrary alloc] init];
void (^ALAssetsLibraryAssetForURLResultBlock)(ALAsset *) = ^(ALAsset *asset) {

if (asset != nil) {

ALAssetRepresentation *rep = [asset defaultRepresentation];
Byte imageBuffer = (Byte)malloc(rep.size);
NSUInteger bufferSize = [rep getBytes:imageBuffer fromOffset:0.0 length:rep.size error:nil];
NSData *imageData = [NSData dataWithBytesNoCopy:imageBuffer length:bufferSize freeWhenDone:YES];

// 这个imageData就是gif的了
} else {}
};

[assetLibrary assetForURL:imageRefURL
resultBlock:ALAssetsLibraryAssetForURLResultBlock
failureBlock:^(NSError *error){
}];

相关文章

网友评论

  • 孙小猴猴猴:你能写的认真点吗?info是什么变量?
    彗星来的那一夜:打开相册选择完成的代理方法- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info,这个info啊

本文标题:iOS 将相册中的动态GIF图转化为NSData类型

本文链接:https://www.haomeiwen.com/subject/alqwzttx.html