Tuesday, April 23, 2013

UIImage UIImageOrientationRight example ios


UIImageOrientation - UIImageOrientationRight
Specifies the possible orientations of an image.
typedef enum {
   UIImageOrientationUp,
   UIImageOrientationDown,   // 180 deg rotation
   UIImageOrientationLeft,   // 90 deg CW
   UIImageOrientationRight,   // 90 deg CCW
   UIImageOrientationUpMirrored,    // as above but image mirrored along
   // other axis. horizontal flip
   UIImageOrientationDownMirrored,  // horizontal flip
   UIImageOrientationLeftMirrored,  // vertical flip
   UIImageOrientationRightMirrored, // vertical flip
} UIImageOrientation;
Constants
UIImageOrientationUp
The default orientation of images. The image is drawn right-side up, as shown here. up orientation
Available in iOS 2.0 and later.
Declared in UIImage.h.
UIImageOrientationDown
The image is rotated 180 degrees, as shown here. down orientation
Available in iOS 2.0 and later.
Declared in UIImage.h.
UIImageOrientationLeft
The image is rotated 90 degrees clockwise, as shown here. right orientation
Available in iOS 2.0 and later.
Declared in UIImage.h.
UIImageOrientationRight
The image is rotated 90 degrees counterclockwise, as shown here. left orientation
Available in iOS 2.0 and later.
Declared in UIImage.h.
Example of UIImageOrientationRight
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();
}
Example of UIImageOrientationRight