UIImagePickerControllerを提示した後、選択した画像名(フォトギャラリーからのもの)を取得する方法を知っている人はいますか?
6933 次
1 に答える
10
ALAssetの助けを借りて、これを達成することができます。
ステップ1:Asset
選択した画像のをUIImagePicker
ステップ2:そのALAssetRepresentationを取得しAsset
ます。
ステップ3:ALAssetRepresentation
クラスにはというプロパティがありますfileName
- (NSString *)filename
ディスク上の表現のファイル名を表す文字列を返します。
このサンプルコードはあなたを助けます...
- (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];
}
注:iOS5以降でのみ機能します。
于 2012-07-13T13:49:20.927 に答える