Graphics Context 学籍摘记

Drawing to a View Graphics Context in iOS

To draw to the screen in an iOS application, you set up a  UIView  object and implement its  drawRect:  method to perform drawing.  You obtain graphics context in your  drawRect:  method by calling the UIKit function  UIGraphicsGetCurrentContext .

The default coordinate system used throughout UIKit is different from the coordinate system used by Quartz. In UIKit, the origin is in the upper-left corner, with the positive-y value pointing downward. The UIView object modifies the CTM of the Quartz graphics context to match the UIKit conventions by translating the origin to the upper left corner of the view and inverting the y-axis by multiplying it by -1.

Creating a PDF Graphics Context

The Quartz 2D API provides two functions that create a PDF graphics context:

  • CGPDFContextCreateWithURL, which you use when you want to specify the location for the PDF output as a Core Foundation URL.

  • CGPDFContextCreate, which you use when you want the PDF output sent to a data consumer. 

iOS Note:  A PDF graphics context in iOS uses the default coordinate system provided by Quartz, without applying a transform to match the UIKit coordinate system. 

Creating a Bitmap Graphics Context

Note:  Bitmap graphics contexts are sometimes used for drawing offscreen. 
iOS Note: iOS applications should use the function UIGraphicsBeginImageContextWithOptions instead of using the low-level Quartz functions described here. If your application creates an offscreen bitmap using Quartz, the coordinate system used by bitmap graphics context is the default Quartz coordinate system. if your application creates an image context by calling the function UIGraphicsBeginImageContextWithOptions, UIKit applies the same transformation to the context’s coordinate system as it does to a UIView object’s graphics context. 
You use the function CGBitmapContextCreate to create a bitmap graphics context. 

Anti-Aliasing

You can turn anti-aliasing off for a particular bitmap graphics context by calling the function  CGContextSetShouldAntialias .You can control whether to allow anti-aliasing for a particular graphics context by using the function CGContextSetAllowsAntialiasing. Pass true to this function to allow anti-aliasing;false not to allow it.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值