简体   繁体   中英

What is a graphic context? (iOS)

What exactly is a graphic context? When drawing with Core Graphic we get a reference to the context. When I look at the documentation it seems like it is an object or so that take care of the correct drawing whether it is for printing, device, pdf and so on.

Could anyone help me to understand what a context really is? I tried reading the documentation but I do not understand. Is it an object that contains information(meta-data) about a system or something?

Thanks in advance

"it seems like it is an object or so that take care of the correct drawing whether it is for printing, device, pdf and so on."

Exactly correct.

You simply write routines that "really" do some drawing (but it could be to anywhere, to any type of thing or device). You don't have to worry about ANYTHING other than drawing in the abstract ... lines, circles, typography, colours and other such nonsense.

-(void)happyDrawing
-(void)sadDrawing
-(void)fancyDrawing

Then -- amazingly -- you can use those anywhere.

-(void)makeSomeFiles
   {
   .. set up a context for making files
   .. happyDrawing
   }
-(void)makeATruGrayScaleBitmap
   {
   .. set up a context for making a gray bitmap
   .. happyDrawing
   }
-(void)drawRect
   {
   .. drawing on your Lisa screen
   .. happyDrawing
   }
-(void)drawRect
   {
   .. drawing on your iPad screen
   .. happyDrawing
   }
-(void)printAPage
   {
   .. set up a context for printing
   .. happyDrawing
   }

I hope it helps!

简而言之,图形在实际呈现之前被渲染或绘制的区域。

The graphics context determines how you are drawing to the screen, be it OpenGL or some 2D library. You should know this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM