|
楼上,正解,苹果App 不能直接访问另外的App ,需要经过获取系统相册App里的图片,然后保存到自己App沙盒里面再操作,主要用到用imagepickercontroller的-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info方法。具体Demo如下:- -(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
-
- //先把图片转成NSData(注意图片的格式)
- UIImage* image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
- NSData *data = UIImagePNGRepresentation(image);;
-
- //图片保存的路径
- NSString * DocumentsPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
- NSFileManager *fileManager = [NSFileManager defaultManager];
- [fileManager createDirectoryAtPath:DocumentsPath withIntermediateDirectories:YES attributes:nil error:nil];
- [fileManager createFileAtPath:[DocumentsPath stringByAppendingString:@"/image.png"] contents:data attributes:nil];
- filePath = [[NSString alloc]initWithFormat:@"%@%@",DocumentsPath, @"/image.png"];
-
- NSLog(@"图片的完整路径是:%@", filePath);
- }
- }
复制代码 |
|