这将带你到图片库,你可以选择图像。
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc]init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imagePickerController animated:YES completion:nil];
这将帮助你选择图像
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
// Dismiss the image selection, hide the picker and
//show the image view with the picked image
[picker dismissViewControllerAnimated:YES completion:nil];
//UIImage *newImage = image;
}
然后你就可以保存此图片的文件目录...
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.png"];
UIImage *image = imageView.image; // imageView is my image from camera
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savedImagePath atomically:NO];
对于点击图片自己使用这个
- (IBAction) takePhoto:(id) sender
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:imagePickerController animated:YES];
}
在iPhone,你必须使用的UIImagePickerController来检索图库图片,您可以通过它保存在NSDocumentsDirectory – booleanBoy
是谢谢你让他们到乌尔应用程序,但我希望有一些示例代码,以便我可以参考。 – Lloydworth
谷歌“UIImagePickerController参考”。转到Apple的网站。 – Akshay