Lk Thanvi
Lk Thanvi

Reputation: 87

UIIMAGE rotation in iPhone without rotating UIIMAGEVIEW On Button Click In Clockwise Or Anticlock wise

I have a UIImageView with is filled with image either taken by camera or picked from the liabray after I assign UIImage to UIImageView I want to rotate it with either clockwise or anticlock wise using 2 button respectively for both on every click image should rotate but without rotationg in superview UIImageView then after I want so save the image in the final position user saved that image...

If there is any method or procedure then please share as i m searching on this query from last many days but not got any acurate solution with proper details and working.

Upvotes: 1

Views: 186

Answers (1)

Giuseppe Mosca
Giuseppe Mosca

Reputation: 1333

Rotation routine ( found this routine on another post but I forget where):

-(UIImage *)rotateImage:(UIImage *)image angleInRadians:(float)angleInRadians {

    UIGraphicsBeginImageContext(image.size);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextRotateCTM(ctx, angleInRadians);
    CGContextDrawImage(ctx, (CGRect){{}, image.size}, image);

    UIImage *imageOut = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return imageOut;
}

Angle in raadians could be M_PI/2 or -M_PI/2 to change landscape to portrait or viceversa

Upvotes: 1

Related Questions