16

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

mfaani
  • 33,269
  • 19
  • 164
  • 293
LuckyLuke
  • 47,771
  • 85
  • 270
  • 434
  • 2
    Appears to be a duplicate of http://stackoverflow.com/questions/4772392/ios-current-graphics-context-what-is-that/4772545#4772545 – hotpaw2 Jan 23 '11 at 22:01

3 Answers3

11

"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!

Fattie
  • 27,874
  • 70
  • 431
  • 719
  • I don't know what you and the OP meant by "whether it is for printing, device, pdf and so on.": I draw a line a CALayer. what does drawing a line mean for a pdf/printer? I mean eventually everything is done with UIKit, Core-Graphics... – mfaani Nov 12 '20 at 22:45
0

To put in simple words, an area where the graphics get rendered or drawn before actually presenting it.

-12

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