Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
287 views
in Technique[技术] by (71.8m points)

iphone - UIImage Rotation custom degrees

I have been using the code in this sample to assist and this works well. http://www.platinumball.net/blog/2009/03/30/iphone-uiimage-rotation-and-mirroring/

I cannot workout how to rotate by a custom amount of degrees between 0 & 360....

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You'll want to do pretty much the same stuff as in that post does in rotate:

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

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

You might need to also translate the CTM in addition to rotating to compensate for the center of rotation. If you want to not crop the edges of the image when rotating, you should increase the size with some basic trig.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...