Programatically I have fetched image from my camera in my app. It has been fetched nicely but when I shift to another view and dismiss that view at that time my image automa
If you are still need some solution just refer this link where I posted my answer for this problem just refer edit and edit 1 also see the last 2 or 3 comments for further reference
Try this property
@property (nonatomic) CGAffineTransform cameraViewTransform
and rotate is with -90 degree and then capture the image. If doesn't work the use the code given by Cocoa Matters.
The bad behavior has now changed with 13.4. Images are now captured with accurate orientation.
The most simplest way to overcome this problem is by scaling the image inside didFinishPickingImage
delegate. You can use the following code to scale by importing a class "UIImage+ImageScaling.h
".
theImage =[UIImage imageWithImage:image scaledToSizeWithSameAspectRatio:CGSizeMake(400, 300)];
// for iphone.
It is due to your image orientation. so keep original image orientation. you will get the image orientation in your UIImagePickerController delegate method
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
sample code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *sourceImage = [info valueForKey:UIImagePickerControllerOriginalImage];
NSData *data = UIImagePNGRepresentation(sourceImage);
UIImage *tmp = [UIImage imageWithData:data];
UIImage *afterFixingOrientation = [UIImage imageWithCGImage:tmp.CGImage
scale:sourceImage.scale
orientation:sourceImage.imageOrientation];
[self.imagePickerController dismissViewControllerAnimated:YES completion:nil];
}
This method works for me,
- (UIImage*) rotateImageAppropriately:(UIImage*)imageToRotate
{
UIImage* properlyRotatedImage;
CGImageRef imageRef = [imageToRotate CGImage];
if (imageToRotate.imageOrientation == 0)
{
properlyRotatedImage = imageToRotate;
}
else if (imageToRotate.imageOrientation == 3)
{
CGSize imgsize = imageToRotate.size;
UIGraphicsBeginImageContext(imgsize);
[imageToRotate drawInRect:CGRectMake(0.0, 0.0, imgsize.width, imgsize.height)];
properlyRotatedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
else if (imageToRotate.imageOrientation == 1)
{
properlyRotatedImage = [UIImage imageWithCGImage:imageRef scale:1.0 orientation:1];
}
return properlyRotatedImage;
}