In iOS Core Graphics, what is a graphicsContext?

China☆狼群 提交于 2019-12-11 17:48:39

问题


When we do:

CGContextRef ctx = UIGraphicsGetCurrentContext();

what exactly is ctx? Apparently it's a struct. Where is the struct defined? What are its members?


回答1:


It is a pointer to a struct. The struct is opaque. Just use the functions connected with it.




回答2:


What is a graphics context?

A graphics context refers to the graphic destination. Destination can be a window in an application, a bitmap image, a PDF document, or a printer.

If you want to draw on a view, the view is your graphicsContext or if you wish to draw on an image then that image becomes your graphicsContext.

So, if you wish to make custom drawing using CoreGraphics , you must get the graphic context (destination where you want to put your drawing) . After getting the context , drawing can be done using the CoreGraphics function. Almost all CoreGraphics function has a parameter context. So, each time we call the coregraphics function we first get the current context and pass it as a parameter.

How can you obtain a graphics context?

You can obtain a graphics context by using Quartz graphics context creation functions or by using higher-level functions provided in the Carbon, Cocoa, or Printing frameworks. For eg: Quartz provides creation functions for various flavors of Quartz graphics contexts including bitmap images and PDF. The Cocoa framework provides functions for obtaining window graphics contexts. The Printing framework provides functions that obtain a graphics context appropriate for the destination printer.

What a graphics context contains?

It contains drawing parameters and all device-specific information needed to render the paint to the destination.

Source:: https://developer.apple.com/library/ios/documentation/graphicsimaging/conceptual/drawingwithquartz2d/dq_layers/dq_layers.html



来源:https://stackoverflow.com/questions/22740543/in-ios-core-graphics-what-is-a-graphicscontext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!