Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "drawing context" exactly? What is the role of getcontext() method?

What is getContext() method and what is drawing context exactly? why we always pass the string 2d to the getContext() method?

like image 573
Jamna Avatar asked Jul 01 '11 11:07

Jamna


People also ask

What is the purpose of getContext ()?

The getContext() function is the function that you use to get access to the canvas tags 2D drawing functions. As of April 2014, there are two types of context that are available to you: 2d and webgl . These provide you with the API that you use to draw on the canvas.

What is context drawing?

In Computer graphics, a drawing context is an abstraction (class/object) that encapsulates how you are going to draw stuff. At a 100k foot level, computer graphics is about converting drawing commands to pixels (image).

What does getContext mean?

getContext():It returns the Context which is linked to the Activity from which it is called.

What is context in canvas?

The canvas context is an object with properties and methods that you can use to render graphics inside the canvas element. The context can be 2d or webgl (3d). Each canvas element can only have one context. If we use the getContext() method multiple times, it will return a reference to the same context object.


1 Answers

Context is a way to choose what you are going to do with your canvas.

For moment you can use getContext for 2d (2dcanvas) or for 3d (WebGL).

HTML5 Specification say's about getContext : "Returns an object that exposes an API for drawing on the canvas. The first argument specifies the desired API. Subsequent arguments are handled by that API."

You can find specifications for each API there : https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-getcontext

It is also good to know that "webgl" is the correct name for API but for moment, as it is experimental you should use "experimental-webgl" to start creating WebGL content

like image 154
Tim Avatar answered Nov 02 '22 18:11

Tim