|
若是访问 iOS 相册是有个方法:
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);
}
}
|
|