iOS: Overlay on iPhone Camera Preview - ios

I'm using Camera API and invoking the camera.
I want to display a header (for branding) on the top of the camera preview. The header is a png image.
Is it possible? Any help appreciated.
Thanks in advance.

You set overlay view of camera.
Check below link. It will help you the solve the problem.
https://stackoverflow.com/a/8101616/1850983

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.imgPickerCamera = [[UIImagePickerController alloc] init];
self.imgPickerCamera.delegate = self;
self.imgPickerCamera.allowsEditing = YES;
self.imgPickerCamera.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imgPickerCamera.navigationBarHidden = NO;
UIImageView *imageView = [[UIImageView alloc] initWithImage:#"<Your image>"];
imageView.frame = <set frame>;
//setting navigation bar
self.imgPickerCamera.navigationController.navigationItem.titleView = imageView;
// Insert the overlay: OverlayView is a UIView
OverlayView *overlay = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,1024) withImagePicker:self.imgPickerCamera];
self.imgPickerCamera.cameraOverlayView = overlay;
[self presentViewController:self.imgPickerCamera animated:YES completion:NULL];
} else {
[self showAlertWithOKButton:#"Error" message:#"Your device doesn't have camera."];
}

Related

How to open camera with frame in iOS

How to bound iPhone camera inside a frame like below image.
Let the camera opens on full screen but the reading area will be only non blurred background in short i want to develop a screen shown in image.
I have tried this code but it is not working...
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
picker.showsCameraControls = YES;
picker.navigationBarHidden = YES;
picker.view.frame = CGRectMake(0, 10, 200, 20); // NOT WORKING !!!
picker.toolbarHidden = YES;
picker.wantsFullScreenLayout = NO;
// picker.delegate = delegate;
CGAffineTransform transform = CGAffineTransformMakeTranslation(0.0f, 50.0f);
transform = CGAffineTransformScale(transform, 1.2f, 1.2f);
picker.cameraViewTransform = transform;
[self presentViewController:picker animated:YES completion:nil];
how do i do this?
Thanks in advance!
You have to create custom camera for that. As I can see in the image you need to scan barcode. For that you need to use
AVCaptureSession
AVCaptureVideoPreviewLayer

UIPickerController Image Offset with an ImageView overlay subview

I am trying to overlay crosshairs in the camera, but after taking a picture, the image is offset from where it was taken. For example, I will line up the crosshairs with a lightbulb in my house, take the picture, and then the crosshairs will be around 20 pixels higher than the image. Here is my code for presenting the PickerController.
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
UIImageView *overlay = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"crosshairs_img"]];
overlay.center = CGPointMake((self.view.bounds.size.width/2), overlay.center.y+195);
overlay.alpha = .6;
overlay.contentMode = UIViewContentModeCenter;
overlay.clipsToBounds = YES;
[picker.view addSubview:overlay];
[self presentViewController:picker animated:YES completion:nil];

How to set frame in center xcode

Im making iPhone app using frame, my frame is not in center and it repeats. I want to set in center and I hate when my frames repeats multiple times.
Im using following code:
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
// picker.delegate = self;
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
// creating overlayView
UIView* overlayView = [[UIView alloc] initWithFrame:picker.view.frame];
// letting png transparency be
overlayView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"f2.png"]];
[overlayView.layer setOpaque:NO];
overlayView.opaque = NO;
picker.showsCameraControls = NO;
picker.cameraOverlayView = overlayView;
//[self presentModalViewController:picker animated:YES];
[self presentViewController:picker animated:YES completion:nil];
Am I missing something ?
TNX in advance.
I'm not sure, what you are asking, but maybe changing from frame to bounds could solve you problem:
UIView* overlayView = [[UIView alloc] initWithFrame:picker.view.bounds];

UIImagePickerController dismissing when it shouldn't

I am trying to create a custom camera overlay, but am having some problems. The capture view works great, but I would like to show another view where the user can edit the photo after the image is captured. The problem is that when a photo is taken, the view with the photo is automatically dismissed. How would I fix this so that I can show another view controller after the user takes a photo.
Here is how I create the picker:
self.cameraPicker = [[UIImagePickerController alloc] init];
self.cameraPicker.delegate = self;
self.cameraPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.cameraPicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
self.cameraPicker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
self.cameraPicker.showsCameraControls = NO;
self.cameraPicker.allowsEditing = YES;
self.cameraPicker.navigationBarHidden = YES;
self.cameraPicker.toolbarHidden = YES;
self.cameraPicker.videoQuality = UIImagePickerControllerQualityTypeIFrame1280x720;
self.frontFacing = NO;
self.gridShowing = NO;
self.showingFlash = NO;
// Insert the overlay
CameraOverlayView *overlay = [[CameraOverlayView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
self.cameraPicker.cameraOverlayView = overlay;
overlay.delegate = self;
[self.navigationController presentViewController:(UIViewController *)self.cameraPicker animated:YES completion:nil];
Here is how I take the photo, after this is called, the viewController is dismissed:
, which I do not want:
[self.cameraPicker takePicture];

Black view at bottom when using custom camera overlay view (UIImagePickerController)

I want to use custom camera overlay view. Below is the code for it.
imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.delegate = self;
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imagePicker.showsCameraControls = NO;
self.imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
self.imagePicker.toolbarHidden = YES;
self.imagePicker.wantsFullScreenLayout = YES;
self.imagePicker.navigationBarHidden = YES;
self.imagePicker.cameraOverlayView = [self cameraOverlayView];
The issue is there is a black background at bottom and I don't get from where it is coming.
What is wrong in code?
Try cameraViewTransform for full screen.
CGFloat camScaleup = 2;
imagePicker.cameraViewTransform = CGAffineTransformScale(imagePicker.cameraViewTransform, camScaleup, camScaleup);

Resources