Camera orientation in landscape only in iphone - iphone

In my application I am using camera to take photos, and I want to use a image as overlay on the camera. the camera should show the landscape right only as my application is in landscape right mode. I am adding the UIImagePicker as subview over the view , and i am using the below code to change it to landscape right mode
CGAffineTransform transform=imgPicker.view.transform;
transform=CGAffineTransformRotate(transform, -90*M_PI/180);
transform=CGAffineTransformTranslate(transform, -52, -47);
[imgPicker setCameraViewTransform:transform];
And while I am adding any UIImageView as overlay for the camera, the imageview is not adding as landscape right. its adding in portrait.
This is my code:
picker=[[UIImagePickerController alloc] init];
picker.delegate=self;
picker.sourceType=UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls=NO;
[picker setCameraFlashMode:UIImagePickerControllerCameraFlashModeOff];
[self.view addSubview:picker.view];
picker.view.frame=CGRectMake(0, 0, 480, 320);
picker.cameraOverlayView.frame=picker.view.frame;
CGAffineTransform transform=picker.view.transform;
transform=CGAffineTransformRotate(transform, -90*M_PI/180);
transform=CGAffineTransformTranslate(transform, -52, -47);
[picker setCameraViewTransform:transform];
[picker setWantsFullScreenLayout:YES];
[picker shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight];
UIView *theView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 120, 120)];
theView.backgroundColor = [UIColor yellowColor];
[picker setCameraOverlayView:theView];
Please tell me where I am doing wrong
Thanks in advance

Related

Using launch image as ViewController background image

I created my 3 launch images (Default Default#2x Default-568#2x) at their appropriate resolutions. I'd like to use these images as the background image of my initial View Controller.
However, when I designed my launch images, I did it with the statusbar in mind and left that area blank. When I try to set the background image of the View Controller to the launch image using the following code, my launch image begins at the bottom of my status bar and the blank area is visible. Essentially, my 640x1136 launch image is being squeezed into a 640x1096 space. What is the proper way to do what I'm attempting?
UIImage *backgroundImage = [[UIImage alloc]init];
if ([[UIScreen mainScreen] bounds].size.height == 568) {
backgroundImage = [UIImage imageNamed:#"Default-568h#2x"];
}
else{
backgroundImage = [UIImage imageNamed:#"Default"];
}
UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:backgroundImage];
[backgroundImageView setFrame:[[self view] bounds]];
[[self view] addSubview:backgroundImageView];
Update:
I replaced:
[backgroundImageView setFrame:[[self view] bounds]];
With:
[backgroundImageView setFrame:CGRectMake(0 ,-20,self.view.frame.size.width , self.view.frame.size.height+20)];
And it seems to be behaving the way I want now.
Try this:
[self.view setBackgroundColor:[UIColor colorWithPatternImage:backgroundImage]];
Also try not setting backgroundImageView's frame programatically. It should already be the size it should be when you call initWithImage:.
Make use of unedited image which does not contain the blank area. this will work fine.
Check replacing this [backgroundImageView setFrame:[[self view] bounds]]; with the following code.
int statusBarHeight = statusBar.frame.size.height;
backgroundImageView.frame = CGRectMake(0 ,statusBarHeight,self.view.frame.size.width , self.view.frame.size.height-statusBarHeight);

iPhone taking a picture when saving always landscape

I have this iPhone application that let users take a picture and save it in a database online. My problem is that every time an user take a picture and saves it, the picture results to be in landscape, even though it was taken in portrait mode. This results in having the portrait picture stretched.
This is the code I use when taking a picture:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
NSData *imgData=UIImageJPEGRepresentation([info objectForKey:#"UIImagePickerControllerOriginalImage"],1);
UIImage *img=[[UIImage alloc] initWithData:imgData];
if(img.size.width < img.size.height){
NSLog(#"width < height");
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
}
else{
NSLog(#"width > height");
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 460, 320)];
}
imageView.image = img;
[img release];
[[self view] fillPreviewWithImg: imageView];
[[self view] setImage: imageView.image];
}
Basically what I do is take the picture, create a UIImage, check if it's portrait or landscape, create the corresponding UIImageView and then set the image into the UIImageView. After that I just call a couple of methods to set up the image in the main view.
I believe the problem with stretching is not bounded to the PHP but to the Objective-C code, but I can't really see how or why this behavior happens.
Does anyone of you have an idea?
Thanks,
Masiar
Have a look at the imageOrientation property of the UIImage class. You can have an image that is 320 wide and 480 high, but with an orientation of Landscape. This is contained in the EXIF information and it is up to the viewing program to use this orientation information to rotate the image appropriately. Just checking the width and height of the image is not sufficient to know the orientation and this is causing your stretching that you are seeing.

uiimageview aspectfit question

I've use a imagepicker to select image from my photo library, then i display that image in an uiimageview. Landscape photo works fine but there is some weirdness to the portrait image. The portrait image suppose to fill up the left and right empty space but it's not.
Cant figure out why the picture wont fill up the left and right space cause the imageview frame did specify the mainScreen bounds.
If i take away the aspectfit then the potrait image is nicely display but the landscape image is stretched to fill up the whole imageview.
My code is as follow:
CGRect frame = [[UIScreen mainScreen] bounds];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:frame];
UIImageView *selectedImageView = [[UIImageView alloc] initWithFrame:frame];
selectedImageView.image = image;
selectedImageView.contentMode = UIViewContentModeScaleAspectFit;
[scrollView addSubview:selectedImageView];
[selectedImageView release];
scrollView.delegate = self;
[self.view addSubview:scrollView];
[scrollView release];
Here is what it looks like:
Edit: My goal is to display the photo like it's been display in Photos album, start out as fitting in the view and allow zoom in to a certain limit.
Try out
UIImageView *logoImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"logo_bg.png"]];
[logoImageView setFrame:CGRectMake(0, 0, 320, [UIImage imageNamed:#"logo_bg.png"].size.height)];
[mainView addSubview:logoImageView];

How to display UIWebView with correct zoom scale in landscape

I create UIWebView and set autorotate like this:
- (void)loadView
{
self.view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)] autorelease];
UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
webview.delegate = self;
webview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"bg_darkgreen_320x312.png"]];
webview.dataDetectorTypes = UIDataDetectorTypeLink;
webview.multipleTouchEnabled = YES;
webview.scalesPageToFit = YES;
webview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[webview loadHTMLString:#"<meta name=\"viewport\" content=\"width=320\">content ..." baseURL:nil];
[self.view addSubview:webview];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
It works perfectly when I rotate it in landscape without zooming. It will display full screen on both rotation.
The problem is if I zoom-out or a little bit zoom-in in portrait mode and then rotate it in landscape, webview still zoom with the same size of portrait mode and it has black space like in picture > http://cl.ly/1o3c4712053C3T2C2H2z
It's width in landscape is correct, 480px (you can see its scrollbar is on most right of screen). I don't understand why webview don't display full screen.
What I do wrong?
Is there any way to fix this?
Please help.
Thanks in advance.
In order to achieve your effect you need to set the zoomScale to 0 on rotation. See my full answer here: UIWebView content not adjusted to new frame after rotation

UIWebView frame to fill screen when loaded landscape and portrait

I am adding a UIWebView to my view, which works fine when I am in portrait. But when I load that same UIWebView in landscape it does not fill the screen. I suspect it comes from how I am setting the frame:
CGRect screen = [[UIScreen mainScreen] bounds];
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, screen.size.width, screen.size.height)];
webView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
webView.scalesPageToFit = YES;
Is there a better way to do this so it will load correctly in both landscape and portrait, and fill the screen when rotated?
How sure are you that the parent view is resizing to the full width? UIWebView subview will not go larger than it's parent...
I had same problem.. After i Logged the self.view.frame.size.width i was surprised to find out thats it was 320 instead of 480. The solution to this was :
- (void)viewWillAppear:(BOOL)animated {
[self.view setBounds:CGRectMake(0.f, 0, self.view.frame.size.width, self.view.frame.size.height)];
[self.view setCenter:CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2)];
[(UIWebView*)myWebView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];}
Seems that the correct size of self.frame is returned just before showing the view :)