標籤:
通過IUImagePickerController方法擷取系統的相簿,而想要得到從系統相簿得到的圖片的資訊需要以下幾步:
1:獲得從UIImagePicker選擇的照片的Assert;
2:得到Assert的ALAssertRepresentation;
3:ALAssertRepresentation有個filename的屬性
代碼具體如下:
該方法是UIImagePickerController中的代理中的方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 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] autorelease]; [assetslibrary assetForURL:imageURL resultBlock:resultblock failureBlock:nil]; } 注:想要用到以上操作,需要引入以下的內容
#import <AssetsLibrary/ALAsset.h>#import <AssetsLibrary/ALAssetsLibrary.h>#import <AssetsLibrary/ALAssetsGroup.h>#import <AssetsLibrary/ALAssetRepresentation.h>
如下效果:
原文地址:點擊
【學習ios之路:UI系列】擷取通過UIImagePackerController擷取的系統相簿圖片的名稱資訊