Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 545
LuckyLuke Avatar asked Jan 23 '11 18:01

LuckyLuke


People also ask

What is a context in core graphics?

A CoreGraphics context represents drawing state. It contains things such as the current transformation matrix, the width and height of any lines to be drawn, the fill color, the stroke color, and a bunch of other information about how the computer should draw things.

What is core graphics in IOS?

The Core Graphics framework is based on the Quartz advanced drawing engine. It provides low-level, lightweight 2D rendering with unmatched output fidelity.

What is graphics context in Java?

A graphics context is an object belonging to the class, Graphics. Instance methods are provided in this class for drawing shapes, text, and images. Any given Graphics object can draw to only one location. In this chapter, that location will always be one of Java's GUI components, such as an applet.

What is UIGraphicsGetCurrentContext?

UIGraphicsGetCurrentContext()Returns the current graphics context.


1 Answers

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

like image 135
Fattie Avatar answered Oct 14 '22 21:10

Fattie