Harshal
Harshal

Reputation: 201

How can I rotate UIImage on clicking rotate button

I would like to rotate UIImage not the UIImageView on clicking rotate button not on orientation change. Please reply.

Upvotes: 0

Views: 944

Answers (3)

Tatvamasi
Tatvamasi

Reputation: 2547

You can use imageWithCGImage:scale:orientation: (available from 4.0)

Upvotes: 1

Nitish
Nitish

Reputation: 14113

CGSize size =  sizeOfImage;
UIGraphicsBeginImageContext(size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextRotateCTM(ctx, angleInRadians);
CGContextDrawImage(UIGraphicsGetCurrentContext(),
  CGRectMake(0,0,size.width, size.height),
  image);

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;

Upvotes: 1

Related Questions