如何将相册中的动态GIF图转化成NSData类型
展开全部
StackOverFlow就是NB啊!!
NSURL *imageRefURL = [info valueForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibrary* assetLibrary = [[ALAssetsLibrary alloc] init];
void (^ALAssetsLibraryAssetForURLResultBlock)(ALAsset *) = ^(ALAsset *asset) {
if (asset != nil) {
[[NSFileManager defaultManager] removeItemAtPath:[PaiKeUnity getPrevImgPath] error: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 writeToFile:[PaiKeUnity getPrevImgPath] atomically:YES];
[self setPrevImage];
}
else {
}
};
[assetLibrary assetForURL:imageRefURL
resultBlock:ALAssetsLibraryAssetForURLResultBlock
failureBlock:^(NSError *error){
}];
[assetLibrary release];
NSURL *imageRefURL = [info valueForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibrary* assetLibrary = [[ALAssetsLibrary alloc] init];
void (^ALAssetsLibraryAssetForURLResultBlock)(ALAsset *) = ^(ALAsset *asset) {
if (asset != nil) {
[[NSFileManager defaultManager] removeItemAtPath:[PaiKeUnity getPrevImgPath] error: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 writeToFile:[PaiKeUnity getPrevImgPath] atomically:YES];
[self setPrevImage];
}
else {
}
};
[assetLibrary assetForURL:imageRefURL
resultBlock:ALAssetsLibraryAssetForURLResultBlock
failureBlock:^(NSError *error){
}];
[assetLibrary release];
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询