UIPickerController Image Offset with an ImageView overlay subview - ios

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

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

iOS: Overlay on iPhone Camera Preview

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."];
}

Capture and custom crop image with camera iOS

I am using UIImagePickerController to capture the image. Now I want to crop the image. I am using cameraOverlayView method of UIImagePicker but it does not allow to move my cropping view. I want my cropping view should be moveable and resizable so that user can select image portion to use.
I am using the following code:
UIImagePickerController *cameraPicker = [[UIImagePickerController alloc] init];
cameraPicker.delegate = self;
cameraPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraPicker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
UIView *overlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
cameraPicker.cameraOverlayView =overlay;
cameraPicker.allowsEditing = NO;
[self presentViewController:cameraPicker animated:YES completion:nil];
Can anyone suggest what can I do?
- (void)pickphoto:(UIImagePickerControllerSourceType)sourceType
{
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.navigationBar.tintColor=[UIColor blackColor];
imagePicker.navigationItem.title=#"Photo Albums";
imagePicker.AllowsEditing = TRUE;
imagePicker.delegate = self;
imagePicker.sourceType = sourceType;
[self presentModalViewController:imagePicker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
_imageV.image = image;
_imageV.layer.borderColor=[UIColor whiteColor].CGColor;
_imageV.layer.borderWidth=1.0;
[imagePicker dismissModalViewControllerAnimated:YES];
}

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

How to add the UIImagePickerController in the custom view?

How to add the UIImagePickerController in the view ? If I add the image picker to the view, its show on the full screen. I need to show the on the centre of the view, But UIImagePickerController hide the navigation bar.
How add the UIImagePickerController in the view and also show the navigation bar ?
I am using the following code, I got the output like this(screenshot).
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
imagePicker.showsCameraControls = NO;
imagePicker.navigationBarHidden = NO;
imagePicker.toolbarHidden = YES;
imagePicker.wantsFullScreenLayout = NO;
imagePicker.delegate = self;
imagePicker.cameraOverlayView = cameraOverlayView;
[self presentViewController:imagePicker animated:NO completion:nil];
I need some for show the navigation bar while add the UIImagePickerController in the view. Thanks in advance.
If you are develop application for iPad then you can use popoverviewcontroller to show imagepickerviewcontroller with navigation bar
please see thie link :
How to use UIImagePickerController in iPad?
Correct way to customize media capture here using Assets Library.
Simple way (in some cases) is using overlay view with frame size of whole screen and add controls on that view which simulate navigation bar.
if (_pickerOverlay == nil) {
_pickerOverlay = [[UIView alloc] initWithFrame:self.view.bounds];
//red transparent tint for demo
_pickerOverlay.backgroundColor = [UIColor colorWithRed:1.0
green:0.0
blue:0.0 alpha:0.6];
UIButton *btnBack = [UIButton buttonWithType:UIButtonTypeSystem];
btnBack.frame = CGRectMake(20, 20, 250, 40);
[btnBack setTitle:#"Custom buttom" forState:UIControlStateNormal];
btnBack.backgroundColor = [UIColor whiteColor];
[_pickerOverlay addSubview:btnBack];
}
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = NO;
picker.cameraOverlayView = _pickerOverlay;
[self presentViewController:picker animated:YES completion:nil];

Resources