I have an simple UIImagePickerController where I hide the camera controls and set the sourceType to the camera. This opens the live camera preview right away but there's about a 50px hight black bar at the bottom of the viewer. Any idea how to get rid of this?
Thanks Usman for the link. The ratio seems to be a bit different from what's suggested in the blog. The ratio of 1.23 works for iPhone 4 and 4s. Also, in order to preserve the aspect ratio, I suggest scaling both x and y.
picker = [[UIImagePickerController alloc] init];
picker.sourceType = sourceType;
picker.delegate = self;
picker.allowsEditing = NO;
picker.showsCameraControls = NO;
CGAffineTransform cameraTransform = CGAffineTransformMakeScale(1.23, 1.23);
picker.cameraViewTransform = cameraTransform;
I believe this is due to the differing aspect ratio of the camera vs. the iPhone screen.
Related
I have set an UIIMagePicker in my app with:
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.modalPresentationStyle = UIModalPresentationFullScreen;
imagePickerController.showsCameraControls = NO;
imagePickerController.navigationBarHidden = YES;
imagePickerController.toolbarHidden = YES;
imagePickerController.wantsFullScreenLayout = YES;
//imagePickerController.cameraViewTransform = CGAffineTransformScale(imagePickerController.cameraViewTransform, 1.0, 1.3);
imagePickerController.delegate = self.overlayView;
[self.view addSubview:imagePickerController.view];
imagePickerController.cameraOverlayView =self.overlayView.view;
All good and fine while the app is in portrait mode. Yet, if I rotate it in landscape a strange issue happen: a black bar appears on the right side and the view is 'rotated', in the sense that if I move the iPhone upward the image moves to the side and viceversa.
If I start in landscape mode, the black bar does not appear (it conversely shows when I rotate to portrait mode on the bottom), but the funny rotating behavior happens all the same.
In both cases the overlay screen seems to fill the screen and also correctly handle rotation.
What might be the issue and how to fix it?
Thanks, Fabrizio
I have an instance of UIImagePickerControler that I have customized to allow me to use my own buttonBar and not Apple's default.
here is the implementation code.
- (void)presentCameraPicker
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
photoPicker = [[UIImagePickerController alloc] init];
photoPicker.delegate = self;
photoPicker.allowsEditing = NO;
photoPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
photoPicker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
photoPicker.showsCameraControls = NO;
cameraOverlayVC.view.frame = CGRectMake(0, 426, 320, 54);
[photoPicker.cameraOverlayView addSubview:cameraOverlayVC.view];
[self presentModalViewController:photoPicker animated:YES];
}
}
I have tested it on both versions, iOS4 (4.3 on a iPodTouch 4th Gen) and iOS5 (5.1 on a iPhone 4S). On the iOS4, when the UIImagePicker is on-screen I can tap on the live view image and I get both the tap-to-focus functionality (and AE) and the default focus square visual indicator, just like in Apple's Camera App. On iOS5 I get the same tap-to-focus functionality, but no visual indicator. I could add a new overlay view to simulate Apple's visual indicator, but on iOS4 I would get two superimposed visual indicators on-screen.
Any ideas or suggestions to solve this issue would be appreciated.
I have the below code in my app which displays a UIImagePicker minus the camera controls.
#define CAMERA_SCALAR 1.32
#implementation CameraViewController
- (id)init {
// Remove standard controls from UIImagePicker and make full screen
if (self = [super init]) {
self.sourceType = UIImagePickerControllerSourceTypeCamera;
self.showsCameraControls = NO;
self.navigationBarHidden = YES;
self.toolbarHidden = YES;
self.wantsFullScreenLayout = YES;
self.cameraViewTransform = CGAffineTransformScale(self.cameraViewTransform, 1, CAMERA_SCALAR);
}
return self;
}
Initially when I removed set showsCameraControls to NO I got a black bar on the screen where the controls had been. To offset this I added in the self.cameraViewTransform line to scale up the view.
This works, however it distorts the image. I think what I need to do is also scale the height by the same ratio as the width.
Can anyone advise me on the best way to do this ?
Thanks in advance !
I may be misinterpreting your question, but to scale the width as well, you can
self.cameraViewTransform = CGAffineTransformScale(self.cameraViewTransform, CAMERA_SCALAR, CAMERA_SCALAR);
instead of
self.cameraViewTransform = CGAffineTransformScale(self.cameraViewTransform, 1, CAMERA_SCALAR);
But of course, this will push the sides of the camera view out of screen.
In principle, I think there is no best choice in this case (showing exactly what the camera shows in fullscreen), because the origin of the problem is the difference of the aspect ratio of the screen/camera. You either have to miss part of the view, or distort the view, is my thinking.
I'm using an picker Controller with a cameraOverlayView to display an image of a product in the camera view. The product image is resized before applying on the overlay.
It works fine on iOS 4.2 but on iOS 4.3 the product image is displayed full size.
pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
UIImageView *imgView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:produitAffiche.img_realite]] autorelease];
// Resize
if(imgView.frame.size.height == 480)
{
//Portrait
imgView.frame = CGRectMake(80.0f, 120.0f, 160.0f, 240.0f);
}
else
{
// Landscape
imgView.frame = CGRectMake(40.0f, 160.0f, 240.0f, 160.0f);
}
imgView.contentMode = UIViewContentModeCenter;
imgView.clipsToBounds = NO;
imgView.contentMode = UIViewContentModeScaleAspectFit;
pickerController.cameraOverlayView = (UIView *) imgView;
I changed the frame of the UIImageView I use as overlay but it's still displayed at 320*480.
I know that the cameraOverlayView have been modified in iOS 4.3 but I don't know what has changed and what I have to do to correct my application.
Thanks for your help.
In iOS 4.3 the overlay view is stretched to full screen. Because you set the content mode to aspect fit, the image is stretched to fit the new view size which is 320x480.
You need to make a transparent UIView that is fullscreen, add the imageview to that view and make the UIView the new overlay view.
UIView *fullscreenView = [[UIView alloc] initWithFrame:CGRectZero];
fullscreenView.backgroundColor = [UIColor clearColor];
....
[fullscreenView addSubview:imgView];
pickerController.cameraOverlayView = fullscreenView;
Found this article that seems to fit the bill. The long and short of it is to use
- (UIImage *)
resizedImageWithContentMode:(UIViewContentMode)contentMode
bounds:(CGSize)bounds
interpolationQuality:(CGInterpolationQuality)quality;
Comment out this line in your code
imgView.clipsToBounds = NO;
It should work.
If you really want to clip, #slf 's answer should help.
try setting these properties of UIImagePicker:
mImagePickerController.showsCameraControls = NO;
mImagePickerController.navigationBarHidden = YES;
mImagePickerController.toolbarHidden = YES;
mImagePickerController.wantsFullScreenLayout = YES;
My problem was actually that a UIImagePicker displayed full-screen on iOS5 did not work on iOS4.3, on an iPad. I was starting the image picker up offscreen, then animating it into view... You would see the shutter image open up, but then the camera view itself was simply transparent with no camera output.
My solution was to not animate that in for iOS4.3 on the iPad. It seems that having the camera view started offscreen was leaving the camera rendering part behind (fixed as I noted in iOS5).
This answer is not quite right for the original question but I place it here for someone that comes into the same issue and hits this question as I did.
I'm initializing an UIImagePickerController like this:
self.cameraController = [[UIImagePickerController alloc] init];
self.cameraController.sourceType = UIImagePickerControllerSourceTypeCamera;
self.cameraController.showsCameraControls = NO;
self.cameraController.navigationBarHidden = YES;
self.cameraController.wantsFullScreenLayout = YES;
The problem is that when this is shown, instead of the camera controls,
I get a black bar in its place.
How can I make UIImagePickerController.frame take all the screen space?
Thanks!
The iPhone's camera has a 4:3 aspect ratio whereas the iPhone's screen's aspect ratio is 3:2. Therefore, the live camera picture does not cover the entire screen. If you want to get rid of the black bars, you have to apply a small scaling transform (e.g. 110%) to the camera view.
Ole is spot on, figure out that aspect ratio conversion. Here is the line of code you are probably going to want to implement it.
self.cameraController.cameraViewTransform = CGAffineTransformScale(CGAffineTransformIdentity, 2, 2);