码迷,mamicode.com
首页 > 其他好文 > 详细

系统相册中获取gif图片 保证取到的图片不会改变

时间:2016-06-14 10:08:03      阅读:263      评论:0      收藏:0      [点我收藏+]

标签:

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]; 

系统相册中获取gif图片 保证取到的图片不会改变

标签:

原文地址:http://www.cnblogs.com/hcx0912/p/5582963.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!