- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
#define radians(degrees) (degrees * M_PI/180)
UIImage *rotate(UIImage *image) {
CGSize size = image.size;;
UIGraphicsBeginImageContext(size);
CGContextRef context = UIGraphicsGetCurrentContext();
// If this is commented out, image is returned as it is.
CGContextRotateCTM (context, radians(90));
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
难道还有什么问题吗?没有想法。
最佳答案
问题是您的上下文正在围绕左上角的 (0,0) 旋转。如果您围绕左上角旋转 90 度,您的所有绘图都将超出上下文范围。您需要一个两步变换将上下文的原点移动到它的中间,然后旋转。您还需要以移动/旋转的原点为中心绘制图像,如下所示:
CGContextTranslateCTM( context, 0.5f * size.width, 0.5f * size.height ) ;
CGContextRotateCTM( context, radians( 90 ) ) ;
[ image drawInRect:(CGRect){ { -size.width * 0.5f, -size.height * 0.5f }, size } ] ;
HTH
关于iphone - 旋转图像上下文 (CGContextRotateCTM) 使其变为空白。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5983090/
这是我使用的代码: 保存上下文 将上下文移动到矩形的中间 旋转上下文 从旋转的原点画一条线 恢复上下文 重复 for i in 1...60 { CGContextSaveGState(ctx
我有一个 UIButton 的子类。 这是我必须尝试旋转它的代码。 -(void)drawRect:(CGRect)rect { CGContextRef context = UIGraphi
我想像下面的代码一样在主屏幕上绘制一个删除按钮,就像删除应用程序按钮一样。 思路是先画十字,然后旋转45度。我的代码有什么问题? self.deleteButton = [[UIButton allo
#define radians(degrees) (degrees * M_PI/180) UIImage *rotate(UIImage *image) { CGSize size = imag
我有一个项目,我必须在用户的拇指下旋转一个大图像,它代表一个表盘,使用轮流选择一年中的一天。我目前正在使用 CGContextRotateCTM() 和 -[UIImage drawInRect:]
我是一名优秀的程序员,十分优秀!