3

After taking image from camera in landscapeLeft and landscapeRight orientation, image save in landscape mode. Result image is attached.

Following is my code and all things I tried:

I am using PHPhotoLibrary to save image in custom album.

 // Take Image Button Method
 - (void)snapButtonPressed:(UIButton *)button
  {
  [self.camera capture:^(LLSimpleCamera *camera, UIImage *image,           NSDictionary *metadata, NSError *error)
        {
        if(!error)
          {

        NSString * info = [NSString stringWithFormat:@"Size: %@  -  Orientation: %ld", NSStringFromCGSize(image.size), (long)image.imageOrientation];
        NSLog(@"IMAGE Meta Data:%@",info);

        [CustomAlbum addNewAssetWithImage:image toAlbum:[CustomAlbum getMyAlbumWithName:CSAlbum] onSuccess:^(NSString *ImageId)
        {
            NSLog(@"IMAGE ID:%@",ImageId);
            recentImg = ImageId;
        }
           onError:^(NSError *error)
        {
            NSLog(@"probelm in saving image");
        }];
    }
    else
    {
        NSLog(@"An error has occured: %@", error);
    }
 }
      exactSeenImage:YES];
}
  • List item

enter image description here

Mukesh
  • 777
  • 7
  • 20
  • You need to keep the exif information from the original pictures, but I haven't found any information to this regarding PHPhotoLibrary. MAybe you have better luck, now that you know that the problem is located in the loss of exif rotation information. – mondjunge Jun 24 '16 at 08:40
  • @mukesh are you check my code? – HariKrishnan.P Jun 27 '16 at 12:58

1 Answers1

1

I have use this method to implement the fix image rotation, while capture the image from the camera. I think this is useful for you.

- (UIImage *) fixrotation:(UIImage *)image {


if (image.imageOrientation == UIImageOrientationUp) return image;
CGAffineTransform transform = CGAffineTransformIdentity;

switch (image.imageOrientation) {
    case UIImageOrientationDown:
    case UIImageOrientationDownMirrored:
        transform = CGAffineTransformTranslate(transform, image.size.width, image.size.height);
        transform = CGAffineTransformRotate(transform, M_PI);
        break;

    case UIImageOrientationLeft:
    case UIImageOrientationLeftMirrored:
        transform = CGAffineTransformTranslate(transform, image.size.width, 0);
        transform = CGAffineTransformRotate(transform, M_PI_2);
        break;

    case UIImageOrientationRight:
    case UIImageOrientationRightMirrored:
        transform = CGAffineTransformTranslate(transform, 0, image.size.height);
        transform = CGAffineTransformRotate(transform, -M_PI_2);
        break;
    case UIImageOrientationUp:
    case UIImageOrientationUpMirrored:
        break;
}

switch (image.imageOrientation) {
    case UIImageOrientationUpMirrored:
    case UIImageOrientationDownMirrored:
        transform = CGAffineTransformTranslate(transform, image.size.width, 0);
        transform = CGAffineTransformScale(transform, -1, 1);
        break;

    case UIImageOrientationLeftMirrored:
    case UIImageOrientationRightMirrored:
        transform = CGAffineTransformTranslate(transform, image.size.height, 0);
        transform = CGAffineTransformScale(transform, -1, 1);
        break;
    case UIImageOrientationUp:
    case UIImageOrientationDown:
    case UIImageOrientationLeft:
    case UIImageOrientationRight:
        break;
}

// Now we draw the underlying CGImage into a new context, applying the transform
// calculated above.
CGContextRef ctx = CGBitmapContextCreate(NULL, image.size.width, image.size.height,
                                         CGImageGetBitsPerComponent(image.CGImage), 0,
                                         CGImageGetColorSpace(image.CGImage),
                                         CGImageGetBitmapInfo(image.CGImage));
CGContextConcatCTM(ctx, transform);
switch (image.imageOrientation) {
    case UIImageOrientationLeft:
    case UIImageOrientationLeftMirrored:
    case UIImageOrientationRight:
    case UIImageOrientationRightMirrored:
        // Grr...
        CGContextDrawImage(ctx, CGRectMake(0,0,image.size.height,image.size.width), image.CGImage);
        break;

    default:
        CGContextDrawImage(ctx, CGRectMake(0,0,image.size.width,image.size.height), image.CGImage);
        break;
}

// And now we just create a new UIImage from the drawing context
CGImageRef cgimg = CGBitmapContextCreateImage(ctx);
UIImage *img = [UIImage imageWithCGImage:cgimg];
CGContextRelease(ctx);
CGImageRelease(cgimg);
return img;

 }
HariKrishnan.P
  • 1,204
  • 13
  • 23