Chi*_*ong 3 iphone text objective-c rotation quartz-graphics
我想用Quartz绘制一些文本.现在该应用程序绘制 alt文本http://www.freeimagehosting.net/uploads/71a84c9b49.png,但我希望它显示为"0123456789".有没有办法显示其正常方向?
这是我的代码:
//set image view
drawImage = [[UIImageView alloc] initWithImage:nil];
drawImage.frame = self.view.frame;
[self.view addSubview:drawImage];
UIGraphicsBeginImageContext(self.view.frame.size); // begin
// current context
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSelectFont(context, "Courier", 40, kCGEncodingMacRoman);
CGFloat white[] = {1.0, 1.0, 1.0, 1.0};
CGContextSetFillColor(context, white);
CGContextShowTextAtPoint(context, 0, 30, "0123456789", strlen("0123456789"));
// get image
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext(); // end
Run Code Online (Sandbox Code Playgroud)
Chi*_*tel 14
在Quartz中,图像将颠倒,因为其Y轴是反转的.
iPhone的Y轴从上到下呈正值,即原点位于左上角,而在Quartz和OpenGL中,坐标与良好的旧几何相同,即左下角的原点.
以下是解决Quartz反演问题的一些代码:
CGContextRef ctx = UIGraphicsGetCurrentContext();
// Tanslate and scale upside-down to compensate for Quartz's inverted coordinate system
CGContextTranslateCTM(ctx, 0.0, rect.size.height);
CGContextScaleCTM(ctx, 1.0, -1.0);
Run Code Online (Sandbox Code Playgroud)
这是一篇有趣的帖子,作者说新加坡的一个团队放弃了一个iPhone项目,因为这个倒置问题他们无法弄清楚:http://trandangkhoa.blogspot.com/2009/07/iphone-os-绘制图像和- stupid.html
| 归档时间: |
|
| 查看次数: |
5590 次 |
| 最近记录: |