UIImagePickerView控制器 - 图像路径 - iphone [英] UIImagePickerView Controller - image path - iphone
问题描述
UIImagePickerView
控制器会传回 NSData
的图片,
UIImagePickerView
Controller returns NSData
of image,
我需要将图片的路径存储为varchar数据类型。
My requirement is to store the path of an image as a varchar data type.
从 UIImagePickerView选择一个图片
,我如何获得iPhone的照片库的选定图像的完整路径?
After selecting an image from UIImagePickerView
, how can I obtain the complete path of the selected image of Photo Gallery of iPhone?
我的应用程序不必担心在我的应用程序中存储图像。
My application won't have to worry about storing images within my application. The images are already stored on the iPhone's photo Gallery.
提前感谢。
推荐答案
这是不可能的。 UIImagePickerController会给你一个 UIImage *
,你必须将它转换为 NSData
自己,并将它存储在你的本地沙箱。没有SDK批准的方式来访问用户照片库中的图片(出于安全考虑)。
This is not possible. The UIImagePickerController will give you a UIImage*
, and you have to convert it into NSData
yourself, and store it in your local sandbox. There is no SDK-approved way to access the images in the user's photo gallery (for security reasons).
假设您使用的是SDK 3.0,这里是一个函数返回选择器,将它保存到磁盘,在应用程序的文档目录(这应该工作,尽管我可能在某个地方有一个小错误):
Assuming you're using SDK 3.0, here is a function on the return of the picker that will save it to the disk, in your application's documents directory (this should work, though I may have a small mistake somewhere):
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// Dismiss the picker
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
// Get the image from the result
UIImage* image = [info valueForKey:@"UIImagePickerControllerOriginalImage"];
// Get the data for the image as a PNG
NSData* imageData = UIImagePNGRepresentation(image);
// Give a name to the file
NSString* imageName = @"MyImage.png";
// Now, we have to find the documents directory so we can save it
// Note that you might want to save it elsewhere, like the cache directory,
// or something similar.
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
// Now we get the full path to the file
NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imageName];
// and then we write it out
[imageData writeToFile:fullPathToFile atomically:NO];
}
这篇关于UIImagePickerView控制器 - 图像路径 - iphone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!