如何在iphone中获取通过照片库选取的图像名称? [英] How can i get the name of image picked through photo library in iphone?

查看:160
本文介绍了如何在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:


  1. 在项目导航器中,选择您的项目

  2. 选择目标

  3. 选择构建阶段选项卡

  4. 打开'链接使用库扩展器的二进制文件

  5. 单击+按钮

  6. 选择框架

  7. (可选)将添加的框架拖放到框架组中

  1. In the project navigator, select your project
  2. Select your target
  3. Select the 'Build Phases' tab
  4. Open 'Link Binaries With Libraries' expander
  5. Click the '+' button
  6. Select your framework
  7. (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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆