I want to make a camera application in which i want to start front camera automatically and capture image without user开发者_JS百科 interaction. thanks in advance.
In addition to Robin's answer, add the following statements (before presentModalViewController:) to ensure that if the device has a front camera, that should be opened by default
if([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]){
self.imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera; //skipping this was crashing my app with some ** Assertion failure.
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}
Please note, if your app is compatible with devices running OS older than 4.0, you will have to put in conditional checks since cameraDevice property is available only in iOS 4.0 and later
The UIImagePickerController
is a higher level abstraction to the camera. Have a look at AVFoundation examples to see how to get to the camera more directly.
The documentation for AVFoundation is here.
To do it while still using the picker, have a look at.1317978. Look around for some examples using UIGetScreenImage()
. It used to be a private API but I think it is now allowed.
You might also want to look around at some examples concerning custom overlay, like this one.
I dont know how much you know about objective-c or iphone development.
so I will tell how to take photos in your iphone app.
First you should get your self aquatinted with UIImagePickerController class
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html
here is some examples for the same from apple http://developer.apple.com/library/ios/samplecode/PhotoLocations/
http://developer.apple.com/library/ios/samplecode/PrintPhoto/
http://developer.apple.com/library/ios/samplecode/PhotoPicker/
http://developer.apple.com/library/ios/samplecode/iPhoneCoreDataRecipes/
and next here is the code that will help you take the pics if you just place it in your .m file
- (void)selectPhotos
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
}
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
imageView.image = image;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
now get started.
精彩评论