1

I have an app that takes the photos via the camera or select it from the library and save it as jpg in the documents folder. But before saving it, I would like to rotate is by 90degrees.

Hope anyone can help me out here.

Thanks

eemceebee
  • 2,656
  • 9
  • 39
  • 49

3 Answers3

1

For iOS 4 and later:
UIImage imageWithCGImage:scale:orientation:

For iOS 3 and previous:
How to Rotate a UIImage 90 degrees?

static inline double radians (double degrees) {return degrees * M_PI/180;}
UIImage* rotate(UIImage* src, UIImageOrientation orientation)
{
    UIGraphicsBeginImageContext(src.size);

    CGContextRef context = UIGraphicsGetCurrentContext();

    if (orientation == UIImageOrientationRight) {
        CGContextRotateCTM (context, radians(90));
    } else if (orientation == UIImageOrientationLeft) {
        CGContextRotateCTM (context, radians(-90));
    } else if (orientation == UIImageOrientationDown) {
        // NOTHING
    } else if (orientation == UIImageOrientationUp) {
        CGContextRotateCTM (context, radians(90));
    }

    [src drawAtPoint:CGPointMake(0, 0)];

    return UIGraphicsGetImageFromCurrentImageContext();
}
Community
  • 1
  • 1
Marek Sebera
  • 39,650
  • 37
  • 158
  • 244
0

You can do it like

static inline double radians (double degrees) {return degrees * M_PI/180;}
UIImage* rotate(UIImage* src, UIImageOrientation orientation)
{
    UIGraphicsBeginImageContext(src.size);

    CGContextRef context = UIGraphicsGetCurrentContext();

    if (orientation == UIImageOrientationRight) {
        CGContextRotateCTM (context, radians(90));
    } else if (orientation == UIImageOrientationLeft) {
        CGContextRotateCTM (context, radians(-90));
    } else if (orientation == UIImageOrientationDown) {
        // NOTHING
    } else if (orientation == UIImageOrientationUp) {
        CGContextRotateCTM (context, radians(90));
    }

    [src drawAtPoint:CGPointMake(0, 0)];

    return UIGraphicsGetImageFromCurrentImageContext();
}

Taken from here

Community
  • 1
  • 1
Janak Nirmal
  • 22,706
  • 18
  • 63
  • 99
0
img.transform = CGAffineTransformMakeRotation(3.14159265/2);
Rama Rao
  • 1,043
  • 5
  • 22