How to open camera with frame in iOS - 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

Related

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];

Running camera on iPhone (OS 7)

I have code that perfectly works on iPad
self.clockInEmployee = nil;
self.clockInEmployee = [[userInfo userInfo] valueForKey:#"employee"];
self.clockInEmployeeRole = [[userInfo userInfo] valueForKey:#"role"];
CLog (#"PIN %#", self.clockInEmployee.pin);
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = (id)self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = YES;
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
picker.cameraOverlayView = self.cameraOverlay.view;
if (isPhone())
{
picker.view.frame = CGRectMake(0, 748, 1024, 748);
[mainNavController.view addSubview:picker.view];
[UIView animateWithDuration:0.5 animations:^{
picker.view.frame = CGRectMake(0, 0, 1024, 748);
} completion:^(BOOL finished){
[picker viewDidAppear:YES];
}];
}
modViewController = picker;
but on iPhone when it try to launch camera I only observe black screen.
But if I try to launch it like that:
[appPresentingViewController presentViewController:picker animated:YES completion:nil];
it launches successfully. But in my particular project it causes some UI problems, so it can't be used.
How can I make this
if (isPhone())
{
picker.view.frame = CGRectMake(0, 748, 1024, 748);
[mainNavController.view addSubview:picker.view];
[UIView animateWithDuration:0.5 animations:^{
picker.view.frame = CGRectMake(0, 0, 1024, 748);
} completion:^(BOOL finished){
[picker viewDidAppear:YES];
}];
}
work for both iPad and iPhone ?
Please try this:-
//create an overlay view instance
OverlayView *overlay = [[OverlayView alloc]
initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGTH)];
//create a new image picker instance
UIImagePickerController *picker =
[[UIImagePickerController alloc] init];
//set source to video!
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
//hide all controls
picker.showsCameraControls = NO;
picker.navigationBarHidden = YES;
picker.toolbarHidden = YES;
//make the video preview full size
picker.wantsFullScreenLayout = YES;
picker.cameraViewTransform =
CGAffineTransformScale(picker.cameraViewTransform,
CAMERA_TRANSFORM_X,
CAMERA_TRANSFORM_Y);
//set our custom overlay view
picker.cameraOverlayView = overlay;
//show picker
[self presentModalViewController:picker animated:YES];
for further refrence -here
You may like to go through apples sample project of AVCAM it can be found here
what you need to do is something like this:
AVCaptureSession *avcam = [[AVCaptureSession alloc] init];
AVCaptureVideoPreviewLayer *previewLayer =
[AVCaptureVideoPreviewLayer layerWithSession:avcam];
previewLayer.frame = self.previewView.bounds;
[self.previewView.layer addSublayer:previewLayer];

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);

unable to resize UIImagePickerController more than a certain height

I am trying to incorporate UIImagePickerController into my app by adding it through subview. But somehow I am unable to increase its height beyond a certain fixed size(the size in default camera app). Is there a way to increase the height? Like the "Fast camera" app does it.
Here is my code:
self.picker = [[UIImagePickerController alloc] init];
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
self.picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
self.picker.showsCameraControls = NO;
self.picker.navigationBarHidden = YES;
self.picker.toolbarHidden = YES;
self.picker.delegate = self;
[self.picker.view setFrame:CGRectMake(0, 65, 320, 444)];
[self.view addSubview:self.picker.view];
use cameraOverlayView property UIImagePickerController class for custom view
i don't know it exactly you want like.
try this one:
self.picker = [[UIImagePickerController alloc] init];
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
self.picker.showsCameraControls = YES;
self.picker.delegate = self;
[self.picker.view setFrame:CGRectMake(0,0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
[self.navigationController.view addSubview:self.picker.view];
i checked it working good in my app.
Happy Coding...

Resources