设为首页收藏本站

AnyChat技术支持论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 5606|回复: 2
打印 上一主题 下一主题

IOS中如何获取本地相册中图片的地址

[复制链接]

26

主题

71

帖子

236

积分

中级会员

Rank: 3Rank: 3

积分
236
跳转到指定楼层
楼主
发表于 2014-8-8 12:50:57 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
IOS中如何获取本地相册中图片的地址
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

249

主题

2967

帖子

9075

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
9075
沙发
发表于 2014-8-8 13:55:27 | 只看该作者
您好,iOS平台基于安全的原因没有提供获取相册照片地址的API接口,但是可以取得照片对象,有两种解决方案供参考:
1、把取到的对象保存为一个临时文件(可以存在app的当前目录下,app的当前目录下是可以写的),然后传这个临时文件,传完之后再删除;
2、把取到的对象转换为字节缓冲区,用BRAC_TransBufferEx来传。
回复 支持 反对

使用道具 举报

4

主题

41

帖子

278

积分

中级会员

Rank: 3Rank: 3

积分
278
板凳
发表于 2014-8-8 15:19:48 | 只看该作者
楼上,正解,苹果App 不能直接访问另外的App ,需要经过获取系统相册App里的图片,然后保存到自己App沙盒里面再操作,主要用到用imagepickercontroller的-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info方法。具体Demo如下:
  1. -(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
  2.    
  3.         //先把图片转成NSData(注意图片的格式)
  4.         UIImage* image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
  5.         NSData *data = UIImagePNGRepresentation(image);;
  6.             
  7.         //图片保存的路径
  8.         NSString * DocumentsPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];  
  9.         NSFileManager *fileManager = [NSFileManager defaultManager];
  10.         [fileManager createDirectoryAtPath:DocumentsPath withIntermediateDirectories:YES attributes:nil error:nil];
  11.         [fileManager createFileAtPath:[DocumentsPath stringByAppendingString:@"/image.png"] contents:data attributes:nil];     
  12.         filePath = [[NSString alloc]initWithFormat:@"%@%@",DocumentsPath,  @"/image.png"];
  13.         
  14.         NSLog(@"图片的完整路径是:%@", filePath);  
  15.     }
  16. }
复制代码
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|AnyChat ( 粤ICP备13022410号-1 )  

GMT+8, 2024-4-24 22:33 , Processed in 0.110230 second(s), 21 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表