這將帶你到圖片庫,你可以選擇圖像。
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