i'm using UIImagePickerControllerSourceTypeCamera in my app, but a want to add the camera view a subview. not as modal view.
now i'm using
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
[self presentModalViewController:picker animated:YES];
i want to use it like this, but doesn't seem to work ..
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
[picker.view setFrame:CGRectMake(300, 40, 300, 200)];
[self.view addSubview:picker.view];
i know that the UIImagePickerControllerSourceTypeCamera only can be used as modal view.
How is for example Hipstamatic using this for example?
This is possible in iOS 4+ using the AVCaptureSession framework. It's much more complicated than using UIImagePickerController, but you have complete control over input and output. The key to having the camera view as a subview is the following code. Assume you have a subview called previewView that you want to show the camera view:
AVCaptureSession *session = [[AVCaptureSession alloc] init];
AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:session];
previewLayer.frame = self.previewView.bounds;
[self.previewView.layer addSublayer:previewLayer];
There is more setup work to do to give your AVCaptureSession object the correct input and output devices and to actually capture the photos. That can be found in the documentation and examples on the web.
You're right, the only supported methods for displaying a UIImagePickerController seem to be presentModalViewController:animated: or UIPopoverController.
I'm not familiar with Hipstamatic, but chances are it is using AVFoundation, in particular AVCaptureVideoPreviewLayer.
Visit link to get idea how things can be accomplished. Look out for AVCam Demo in developer.apple.com resources for IOS programme. You will definitely get idea how it works. You should be registered developer with APPLE, and thats very easy.
Hope it helps.
Related
In my iPad app i am trying to open Front facing camera in a UIPopOverController.It is behaving in strange behavior.When i first time click on button to open camera,it open front camera and second time it open rear camera again same repeat.once front camera and second time rear camera.While i have also set front camera as a camera device.Here is my code,Please help.
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.delegate = self;
imagePickerController.allowsEditing = YES;
[imagePickerController setCameraCaptureMode:UIImagePickerControllerCameraCaptureModePhoto];
[imagePickerController setCameraDevice:UIImagePickerControllerCameraDeviceFront];
UIPopoverController *popoverController=[[UIPopoverController alloc] initWithContentViewController:imagePickerController];
[popoverController presentPopoverFromRect:((UIButton *)sender).bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
I got my answer my self. I was not releasing imagePickerController.
After releasing it i get every time front camera. ;)
Is it possible to pop the camera (using UIImagePickerControllerSourceTypeCamera) on the iPad 2 inside of a UIPopoverController using presentModalViewController?
Whenever I do it the camera just goes full screen. I need it inside of the UIPopoverController.
This won't work by calling presentModalViewController:animated:. To make the camera show up in a UIPopoverController's UI, then you want something similar to the following:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.allowsEditing = YES;
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
UIPopoverController *popover = [[UIPopoverController alloc]
initWithContentViewController:imagePicker];
[popover presentPopoverFromBarButtonItem:launchCameraButton
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
There is another way to launch the popover from an arbitrary spot in your UI also. The docs should explain that.
I have a UIImagePickerController that is presented as a modal view controller. This works fine, except for when I try to add anything to the camera overlay view.
As soon as I modify the camera overlay view, the default zoom control stops working (although tap to focus still works). If I tap on the view, the zoom slider appears, but I am not able to slide it up and down like usual.
Here's the code I'm using:
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.allowsEditing = NO;
imagePickerController.delegate = self;
imagePickerController.showsCameraControls = YES;
imagePickerController.wantsFullScreenLayout = NO;
[imagePickerController.cameraOverlayView addSubview:overlayView];
[self presentModalViewController:imagePickerController animated:YES];
Has anyone had a similar problem or can see what I'm doing wrong? I know it should work, as I've seen it on other apps that also use the default camera controls.
Thanks :)
After a lot of mucking round I've finally come across a solution. Don't use the cameraOverlayView property, instead add a subview to the UIImagePickerController with a frame of size CGRectZero.
In the following example, overlayView is a custom subclass of UIView which draws an image and passes touches through to the next responder:
OverlayView *overlayView = [[OverlayView alloc] initWithFrame:CGRectZero];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.allowsEditing = NO;
imagePickerController.delegate = self;
imagePickerController.showsCameraControls = YES;
[imagePickerController.view addSubview:overlayView];
statViewController.imagePickerController = imagePickerController;
}
-
And then, everything just works. Not sure if adding a subview to UIImagePickerController is documented and ok with Apple, but heaps of other apps use this (or a similar workaround) so shouldn't cause any submission problems.
i have a TabBarController in which one tab has an ImageView. Besides, i have a button to display the ImagePicker:
- (IBAction)choosePhoto {
// Create image picker controller
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
// Set source to the camera
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
// Delegate is self
imagePicker.delegate = self;
// Allow editing of image ?
[imagePicker setAllowsEditing:NO];
// Show image picker
[tabBarController presentModalViewController:imagePicker animated:NO];
But the problem is that when i press the button in order to launch the ImagePicker i get the message: Received memory warning. Level=1/ Level=2.
I've tried to change the delegate to the View of the tab but it doesn't works neither.
Any idea?
Thanks
A memory warning per se is not a problem. The camera needs an awful lot of memory so it is very common that the system generates a memory warning whenever the camera interface is being displayed. Just make sure to free as much memory as possible in reaction to the warning.
I have troubles using UIImagePicker to take pictures based on the "Taking Pictures with the Camera" chapter from the iPhone programming guide.
Whatever i try all i get is a grey/white screen.
here is my code :
- (void)viewDidLoad {
[super viewDidLoad];
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.allowsEditing = NO;
[self presentModalViewController:imagePicker animated:YES];
}
I've tried to call the imagePicker from the viewDidLoad, viewWillAppear or awakeFromNib, nothing changes.
My viewController implements UINavigationControllerDelegate and UIImagePickerControllerDelegate.
I'm running this on OS3.1 on a first gen iPhone.
Any help would be greatly appreciated !
Thanks,
Vincent.
I would placing that call in viewDidAppear as oposed to viewDidLoad.