我正在从 iphone 应用程序的照片库中挑选一张图像。我将如何检索实际的图像名称。
在.h类中
UIImageView * imageView;
UIButton * choosePhotoBtn;
在 .m 级
-(IBAction) getPhoto:(id) sender
{
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIButton *) sender == choosePhotoBtn)
{
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
else
{
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissModalViewControllerAnimated:YES];
imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}
我如何获得图像的实际名称?
我是 iPhone 新手。请帮我。
提前致谢。
在您的文件中导入 AssetsLibrary:
#import <AssetsLibrary/AssetsLibrary.h>
And, in - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
put
// get the ref url
NSURL *refURL = [info valueForKey:UIImagePickerControllerReferenceURL];
// define the block to call when we get the asset based on the url (below)
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *imageAsset)
{
ALAssetRepresentation *imageRep = [imageAsset defaultRepresentation];
NSLog(@"[imageRep filename] : %@", [imageRep filename]);
};
// get the asset library and fetch the asset based on the ref url (pass in block above)
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:refURL resultBlock:resultblock failureBlock:nil];
这样您就可以在日志中获取图像名称。
*不要忘记添加现有框架:AssetsLibrary.framework
脚步:
- 在项目导航器中,选择您的项目
- 选择您的目标
- 选择“构建阶段”选项卡
- 打开“链接二进制文件与库”扩展器
- 单击“+”按钮
- 选择您的框架
- (可选)将添加的框架拖放到“框架”组中
Source:
&
如何在 Xcode 4 中“添加现有框架”?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)