I want to draw some texts using Quartz. Now the app draws
, but I want it to show as "0123456789". Is there any way to show its normal orientation?
这是我的代码:
//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
在 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);
这是一篇关于它的有趣文章,作者说新加坡的一个团队由于无法解决这个反转问题而放弃了 iPhone 项目:http://trandangkhoa.blogspot.com/2009/07/iphone-os-drawing-image-and-stupid.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)