Camera images are changing the orientation automatically in iphone

Im developing a photo app.

Here i'm using the images from both photo library and also the images taking through camera and displaying it in a image view.

The images from photo library is coming in correct orientation but camera images are displaying in different orientation.

  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
    NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"MyFolder"];
    NSString *imagePath = [dataPath stringByAppendingPathComponent:@"girl.jpg"];

    if ([[NSFileManager defaultManager] fileExistsAtPath:imagePath]) {
        UIImage *image = [UIImage imageWithCGImage:[UIImage imageWithContentsOfFile:imagePath].CGImage scale:bieberImage.image.scale
                                       orientation:NO]; 

     //   bieberImage.transform = CGAffineTransformMakeRotation(1.57079633);


    CABasicAnimation *crossFade = [CABasicAnimation animationWithKeyPath:@"contents"];
    crossFade.duration = 3.0;


        crossFade.fromValue = (id)bieberImage.image.CGImage;

        crossFade.toValue = (id)image.CGImage;



        [self.bieberImage.layer addAnimation:crossFade forKey:@"animateContents"];

        }

Can anyone tell me how can i correct this problem.

Thanks in advance.

Answers


Replace:

        UIImage *image = [UIImage imageWithCGImage:[UIImage imageWithContentsOfFile:imagePath].CGImage scale:bieberImage.image.scale
                                   orientation:NO]; 

With:

        UIImage *image = [UIImage imageWithCGImage:[UIImage imageWithContentsOfFile:imagePath].CGImage scale:bieberImage.image.scale
                                   orientation:UIImageOrientationRight]; 

Edit: Or try this:

 - (UIImage*) rotateImage:(UIImage* )src {

    UIImageOrientation orientation = src.imageOrientation;

    UIGraphicsBeginImageContext(src.size);

    [src drawAtPoint:CGPointMake(0, 0)];
    CGContextRef context = UIGraphicsGetCurrentContext();

     if (orientation == UIImageOrientationRight) {
         CGContextRotateCTM (context, [self radians:90]);
     } else if (orientation == UIImageOrientationLeft) {
         CGContextRotateCTM (context, [self radians:90]);
     } else if (orientation == UIImageOrientationDown) {
         // NOTHING
     } else if (orientation == UIImageOrientationUp) {
         CGContextRotateCTM (context, [self radians:0]);
     }

      return UIGraphicsGetImageFromCurrentImageContext();
 }

 - (CGFloat) radians:(int)degrees {
    return (degrees/180)*(22/7);
  }

Need Your Help

Staying Logged In Using Requests and Python

python-requests

I am trying to log onto a website using python and requests. I'm pretty sure I am logging on properly. The next part is I go to a different page and try to download a file from that page. However, in

What is the proper way to load up a ListBox?

c# .net winforms

What is the proper way to load a ListBox in C# .NET 2.0 Winforms?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.