【发布时间】:2013-06-13 06:41:15
【问题描述】:
我想用CGAffineTransform 绘制 UIimage,但用CGContextConcatCTM 输出错误
我尝试了以下代码:
CGAffineTransform t = CGAffineTransformMake(1.67822, -1.38952, 1.38952, 1.67822, 278.684, 209.129); // transformation of uiimageview
UIGraphicsBeginImageContext(CGSizeMake(1024, 768));
CGContextRef imageContext = UIGraphicsGetCurrentContext();
CGContextDrawImage(imageContext, dragView.frame, dragView.image.CGImage);
CGContextConcatCTM(imageContext, t);
NSLog(@"\n%@\n%@", NSStringFromCGAffineTransform(t),NSStringFromCGAffineTransform(CGContextGetCTM(imageContext)));
输出:
[1.67822, -1.38952, 1.38952, 1.67822, 278.684, 209.129] // imageview transformation
[1.67822, 1.38952, 1.38952, -1.67822, 278.684, 558.871] // drawn image transformation
CGAffineTransform CGAffineTransformMake (
CGFloat a,
CGFloat b,
CGFloat c,
CGFloat d,
CGFloat tx,
CGFloat ty
);
参数b、d、ty变了,怎么解决?
【问题讨论】:
-
您最初是如何得出这些价值观的?
-
另外,图像是倒置显示(或以其他方式显示错误),还是只是您关心的日志输出?
-
是的,这只是日志输出
-
我认为这是核心图形和UIKit坐标系的问题。我不确定.. 但我不知道如何将其转换为 Core Graphics 坐标系。
-
顺便说一句,你真的不应该硬编码这样的大小。根据您正在做的事情,您应该获取视图的框架、窗口的框架或屏幕的框架,并使用其中的大小。
标签: iphone objective-c core-graphics cgcontext cgaffinetransform