头文件添加
#include<AssetsLibrary/AssetsLibrary.h>
选图的方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//图片选取完成后调回主界面
[picker dismissViewControllerAnimated:YES completion:^{}];
_image =[info objectForKey:UIImagePickerControllerEditedImage];
NSLog(@"%@",_image);
_bigImv.image=_image;
NSString*fileName;
UIImage *ysImage = [UIImage imageYaSuoForSize:_image targetSize:CGSizeMake(300, 300)];
if (UIImagePNGRepresentation(ysImage) == nil) {
imageData = UIImageJPEGRepresentation(ysImage, 1);
}else {
imageData = UIImagePNGRepresentation(ysImage);
}
// 获取图片名称
NSURL *imageURL = [info valueForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *representation = [myasset defaultRepresentation];
NSString *fileName = [representation filename];
NSLog(@"fileName : %@",fileName);
};
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init] ;
[assetslibrary assetForURL:imageURL
resultBlock:resultblock
failureBlock:nil];
}