I made an iphone app to capture image from camera and to set that image in next view. But the problem is that image is rotated. i.e landscape image becomes potraite and protraite image becomes landscape.
I have referred many codes but could not get solution.
My code is :
- (void)btnCapturePressed
{
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
picker=[[UIImagePickerController alloc] init];
picker.delegate=self;
[picker setAllowsEditing:YES];
picker.sourceType=UIImagePickerControllerSourceTypeCamera;
//[self.navigationController pushViewController:(UIViewController *)ipc animated:YES];
[self presentModalViewController:picker animated:YES];
[picker release];
}
}
-(void) imagePickerController:(UIImagePickerController *) picker didFinishPickingMediaWithInfo :(NSDictionary *)info
{
UIImage *imageToScale=[info objectForKey:UIImagePickerControllerOriginalImage];
imgView = [[UIImageView alloc] initWithImage:imageToScale];
[picker presentModalViewController:cropper animated:YES];
}
I have also refered the link. with same problem, but could not find the solution.
Please help me.
Thanks.
So for that at the time of image take store the orientation of the device and pass it to the method below as parameter
Here just give any name to method and pass the parameter
orientationand the macro I have used here
DegreesToRadians()is as followThis will definitely works.
Happy Coding 🙂
EDIT
If the above code doesn’t work well then use this one
and then call the above function as below
If the image is not in required orientation then add 90 to all of the above
imageRotatedByDegrees‘s argument (i.e. if it is 0 then it will be 0+90) or as you required.EDIT 1