如何使用我的iPhone应用程序拍照? [英] How can I take a photo with my iPhone app?
本文介绍了如何使用我的iPhone应用程序拍照?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在xcode中使用Cocoa编写了一个iPhone应用程序。我找不到任何教程或示例代码,显示如何用内置相机拍照。我如何做到这一点?在哪里可以找到好的信息?
I'm writing an iPhone app with Cocoa in xcode. I can't find any tutorials or sample code that shows how to take photos with the built in camera. How do I do this? Where can I find good info?
谢谢!
推荐答案
其中 takePhoto 和 chooseFromLibrary 是我自己的
确保引用适当按钮的出口到这些方法。
Make sure to reference outlets of appropriate buttons to these methods.
-(IBAction)takePhoto :(id)sender
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
[imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
}
// image picker needs a delegate,
[imagePickerController setDelegate:self];
// Place image picker on the screen
[self presentModalViewController:imagePickerController animated:YES];
}
-(IBAction)chooseFromLibrary:(id)sender
{
UIImagePickerController *imagePickerController= [[UIImagePickerController alloc] init];
[imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
// image picker needs a delegate so we can respond to its messages
[imagePickerController setDelegate:self];
// Place image picker on the screen
[self presentModalViewController:imagePickerController animated:YES];
}
//delegate methode will be called after picking photo either from camera or library
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissModalViewControllerAnimated:YES];
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[myImageView setImage:image]; // "myImageView" name of any UIImageView.
}
这篇关于如何使用我的iPhone应用程序拍照?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文