iphone开发 Quratz 2D 学习 ---什么是 graphics context(图形上下文)

本文深入探讨了iOS应用开发中图形上下文(CGContext)的概念及其使用方法,详细介绍了如何创建、操作和关闭路径,以及如何在路径上绘制直线、曲线等基本图形元素。通过本教程,开发者能够掌握iOS应用中图形绘制的基础技能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.graphics context(图形上下文)一个不透明的数据类型(CGContextRef)。我们可以把graphics context想象成为一个绘图目标。有几种graphics context:bitmap graphics context,PDF graphics context,window graphics context,layer context。
 
2.IOS中获得graphics context是在方法drawRect:中,调用方法 UIGraphicsGetCurrentContext得到上下文。drawRect:方法不需要调用super

CGContextRef c = UIGraphicsGetCurrentContext();


3.调用方法 CGContextMoveToPoint开始一个新的路径,
调用方法 CGContextAddLineToPoint添加一个单一的线条。

4. When you want to construct a path in a graphics context, you signal Quartz by calling the function CGContextBeginPath . Next, you set the starting point for the first shape, or subpath, in the path by calling the function CGContextMoveToPoint. After you establish the first point, you can add lines, arcs, and curves to the path, keeping in mind the following:
  • Before you begin a new path, call the function CGContextBeginPath.

  • Lines, arcs, and curves are drawn starting at the current point. An empty path has no current point; you must call CGContextMoveToPoint to set the starting point for the first subpath or call a convenience function that implicitly does this for you.

  • When you want to close the current subpath within a path, call the function CGContextClosePath to connect a segment to the starting point of the subpath. Subsequent path calls begin a new subpath, even if you do not explicitly set a new starting point.

  • When you draw arcs, Quartz draws a line between the current point and the starting point of the arc.

  • Quartz routines that add ellipses and rectangles add a new closed subpath to the path.

  • You must call a painting function to fill or stroke the path because creating a path does not draw the path. See “Painting a Path” for detailed information.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值