#pragma mark UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
NSURL *imageURL = [info valueForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *representation = [myasset defaultRepresentation];
_picName = [representation filename];
NSLog(@"fileName : %@",_picName);
};
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:imageURL
resultBlock:resultblock
failureBlock:nil];
[picker dismissViewControllerAnimated:YES completion:^{
UIImage *editedImage, *originalImage;
editedImage = [info objectForKey:UIImagePickerControllerEditedImage];
_headImg.image=editedImage;
// 保存原图片到相册中
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
originalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImageWriteToSavedPhotosAlbum(originalImage, self, nil, NULL);
}
}];
}
注释:再工程中导入类库
再次:导入所需头文件: