如何在iphone中获取通过照片库选取的图像名称? [英] How can i get the name of image picked through photo library in iphone?
问题描述
我正在从iphone应用程序中的照片库中选择一张图片。如何检索实际图像名称。
I am picking an image from photo library in iphone application. How will i retrieve the actual image name.
在.h类
UIImageView * imageView;
UIButton * choosePhotoBtn;
in .m class
in .m class
-(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"];
}
我如何获得图像的实际名称?
How will i get the actual name of image ?
我是iphone的新手。请帮帮我。
I m new in iphone. Please help me.
提前致谢。
推荐答案
import AssetsLibrary在您的文件中:
import AssetsLibrary in your file:
#import <AssetsLibrary/AssetsLibrary.h>
并且,在 - (void)imagePickerController:(UIImagePickerController *)选择器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];
因此您将获得日志中的图像名称。
so you'll get the image name in log.
*不要忘记添加现有框架:AssetsLibrary.framework
步骤:
*don't forget to add existing framework: AssetsLibrary.framework Steps:
- 在项目导航器中,选择您的项目
- 选择目标
- 选择构建阶段选项卡
- 打开'链接使用库扩展器的二进制文件
- 单击+按钮
- 选择框架
- (可选)将添加的框架拖放到框架组中
- In the project navigator, select your project
- Select your target
- Select the 'Build Phases' tab
- Open 'Link Binaries With Libraries' expander
- Click the '+' button
- Select your framework
- (optional) Drag and drop the added framework to the 'Frameworks' group
来源:
http://www.raywenderlich.com/forums/viewtopic.php?f=2&p=34901
&
如何添加现有框架在Xcode 4中?
这篇关于如何在iphone中获取通过照片库选取的图像名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!