UIImage Rotation自定义度 [英] UIImage Rotation custom degrees

查看:84
本文介绍了UIImage Rotation自定义度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用此示例中的代码来提供帮助,并且效果很好. http://www.platinumball.net /blog/2009/03/30/iphone-uiimage-rotation-and-mirroring/

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/

我无法锻炼如何将自定义角度旋转0到& 360 ....

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

推荐答案

您将想要做与旋转中的帖子差不多的事情:

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;

除了旋转以外,您可能还需要平移CTM以补偿旋转中心.如果不想在旋转时裁剪图像的边缘,则应通过一些基本的触发来增加尺寸.

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.

这篇关于UIImage Rotation自定义度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆