aboutsummaryrefslogtreecommitdiff
path: root/files/pt-br/web/api/canvasrenderingcontext2d/index.html
blob: 38ec19a3e33932388d77f0c7bb6a3a0205488858 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
---
title: 'Canvas: Contexto de Renderização em "2D"'
slug: Web/API/CanvasRenderingContext2D
tags:
  - API
  - Canvas
  - CanvasRenderingContext2D
  - Games
  - Graphics
  - NeedsTranslation
  - Reference
  - TopicStub
translation_of: Web/API/CanvasRenderingContext2D
---
<div>{{APIRef}}</div>

<div>A interface <strong>Canvas Renderização de Contexto de duas Dimensões (</strong> <strong>CanvasRenderingContext2D</strong>) é usada para desenhar retangulos, textos, imagens e outros objetos na tag ou elemento canvas. Fornece o contexto de renderização em 2D para a superfície de desenho do elemento  {{ HTMLElement("canvas") }}.</div>

<div></div>

<p>Para obter um objeto desta interface, chama-se  {{domxref("HTMLCanvasElement.getContext()", "getContext()")}} em um <code>elemento &lt;canvas&gt;</code>, adicionando "2d" como argumento, veja o exemplo abaixo:</p>

<pre class="brush: js notranslate">var canvas = document.getElementById('meuCanvas'); // em seu HTML esse elemento se parece com &lt;canvas id="meuCanvas"&gt;&lt;/canvas&gt;
var ctx = canvas.getContext('2d');
</pre>

<p>Agora que você possui o contexto de renderização 2D, você pode desenhar dentro deste canvas. Por exemplo:</p>

<pre class="brush: js notranslate">ctx.fillStyle = "rgb(200,0,0)"; // define a cor de preenchimento do retângulo
ctx.fillRect(10, 10, 55, 50);   // desenha o retângulo na posição 10, 10 com 55 pixels de largura e uma altura de 50
</pre>

<p>Veja as propriedades e métodos no menu lateral e abaixo. O <a href="/en-US/docs/Web/API/Canvas_API/Tutorial" title="Canvas tutorial">tutorial canvas</a> tem mais informações, exemplos e recursos.</p>

<h2 id="Desenhando_Retângulos">Desenhando Retângulos</h2>

<p>Existem três métodos que imediatamente desenham retângulos ao canvas.</p>

<dl>
 <dt>{{domxref("CanvasRenderingContext2D.clearRect()")}}</dt>
 <dd>Determina todos os pixels no retângulo definido, pelo ponto inicial (<em>x, y</em>) e tamanho (<em>largura</em>, <em>altura</em>) para preto transparente, apagando qualquer conteúdo desenhado anteriormente.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.fillRect()")}}</dt>
 <dd>Desenha um retângulo preenchido na posição (<em>x, y</em>) com tamanho definido pela <em>largura </em>e <em>altura</em></dd>
 <dt>{{domxref("CanvasRenderingContext2D.strokeRect()")}}</dt>
 <dd>Pinta um retângulo o qual possui um ponto inicial em <em>(x, y)</em> e possui um<em> w</em> <em>width</em>(largura) e um <em>h</em> <em>height</em>(altura) dentro da tela(canvas), usando o estilo de traçado(stroke) atual.</dd>
</dl>

<h2 id="Desenhando_Textos">Desenhando Textos</h2>

<p>Os métodos seguintes são fornecidos para desenhar texto. Veja também o objeto {{domxref("TextMetrics")}} para propriedades de texto.</p>

<dl>
 <dt>{{domxref("CanvasRenderingContext2D.fillText()")}}</dt>
 <dd>Desenha(preenche) um texto fornecido, em uma posição fornecida(<em>x,y</em>).</dd>
 <dt>{{domxref("CanvasRenderingContext2D.strokeText()")}}</dt>
 <dd>Desenha(traçados) um texto fornecido, em uma posição fornecida(<em>x,y</em>).</dd>
 <dt>{{domxref("CanvasRenderingContext2D.measureText()")}}</dt>
 <dd>Retorna um objeto {{domxref("TextMetrics")}} .</dd>
</dl>

<h2 id="Estilos_de_linha">Estilos de linha</h2>

<p>Os seguintes métodos e propriedades, controlam como as linhas são desenhadas.</p>

<dl>
 <dt>{{domxref("CanvasRenderingContext2D.lineWidth")}}</dt>
 <dd>Largura das linhas. Padrão: <code>1.0</code></dd>
 <dt>{{domxref("CanvasRenderingContext2D.lineCap")}}</dt>
 <dd>Tipos de pontas no final das linhas. Valores possíveis: <code>butt</code> (padrão), <code>round</code>, <code>square</code>.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.lineJoin")}}</dt>
 <dd>Define o tipo de encontro entre duas linhas. Possíveis valores: <code>round</code>, <code>bevel</code>, <code>miter</code> (default).</dd>
 <dt>{{domxref("CanvasRenderingContext2D.miterLimit")}}</dt>
 <dd>Relação do limite de esquadria. Padrão: <code>10</code>.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.getLineDash()")}}</dt>
 <dd>Retorna a matriz de padrão de traço de linha atual contendo um número par de números não negativos.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.setLineDash()")}}</dt>
 <dd>Define o padrão de traço de linha atual.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.lineDashOffset")}}</dt>
 <dd>Especifica onde iniciar uma matriz de traços em uma linha.</dd>
</dl>

<h2 id="Estilos_de_textos">Estilos de textos</h2>

<p>As propriedades abaixo controlam a estilização do texto a ser apresentado:</p>

<dl>
 <dt>{{domxref("CanvasRenderingContext2D.font")}}</dt>
 <dd>Configuração da fonte. Valor padrão: <code>10px sans-serif</code>.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.textAlign")}}</dt>
 <dd>Alinhamento do texto. Possíveis valores: <code>start</code> (padrão), <code>end</code>, <code>left</code>, <code>right</code> or <code>center</code>.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.textBaseline")}}</dt>
 <dd>Configuração de alinhamento da linha de base (Baseline). Possíveis valores: <code>top</code>, <code>hanging</code>, <code>middle</code>, <code>alphabetic</code> (padrão), <code>ideographic</code>, <code>bottom</code>.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.direction")}}</dt>
 <dd>Direção do texto. Possívels valores: <code>ltr, rtl</code>, <code>inherit</code> (padrão).</dd>
</dl>

<h2 id="Estilos_de_preenchimento_e_traço">Estilos de preenchimento e traço</h2>

<p>O estilo de preenchimento é usado para cores e estilos dentro das formas e o estilo de traço é usado para as linhas ao redor das formas.</p>

<dl>
 <dt>{{domxref("CanvasRenderingContext2D.fillStyle")}}</dt>
 <dd>Cor ou estilo para usar formas internas. Padrão <code>#000</code> (preto).</dd>
 <dt>{{domxref("CanvasRenderingContext2D.strokeStyle")}}</dt>
 <dd>Cor ou estilo a ser usado para as linhas em torno das formas. Padrão: <code>#000</code> (preto).</dd>
</dl>

<h2 id="Gradientes_e_padrões">Gradientes e padrões</h2>

<dl>
 <dt>{{domxref("CanvasRenderingContext2D.createLinearGradient()")}}</dt>
 <dd>Cria um gradiente linear ao longo da linha fornecida pelas coordenadas representadas pelos parâmetros.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.createRadialGradient()")}}</dt>
 <dd>Cria um gradiente radial dado pelas coordenadas dos dois círculos representados pelos parâmetros.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.createPattern()")}}</dt>
 <dd>Cria um padrão usando a imagem especificada (uma {{domxref("CanvasImageSource")}}). Ele repete a fonte nas direções especificadas pelo argumento de repetição. Este método retorna um {{domxref("CanvasPattern")}}.</dd>
</dl>

<h2 id="Sombras">Sombras</h2>

<dl>
 <dt>{{domxref("CanvasRenderingContext2D.shadowBlur")}}.</dt>
 <dd>Especifica o efeito de desfoque. Padrão: <code>0</code>.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.shadowColor")}}</dt>
 <dd>Cor da sombra. Padrão: fully-transparent black (preto totalmente transparente).</dd>
 <dt>{{domxref("CanvasRenderingContext2D.shadowOffsetX")}}</dt>
 <dd>Distância horizontal em que a sombra será deslocada. Padrão: <code>0</code>.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.shadowOffsetY")}}</dt>
 <dd>Distância vertical em que a sombra será deslocada. Padrão: <code>0</code>.</dd>
</dl>

<h2 id="Caminhos">Caminhos</h2>

<p>Os seguintes métodos podem ser usados para manipular caminhos de desenhos.</p>

<dl>
 <dt>{{domxref("CanvasRenderingContext2D.beginPath()")}}</dt>
 <dd>Inicia um novo caminho esvaziando a lista de subcaminhos. Chame esse método quando você quiser criar um novo caminho.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.closePath()")}}</dt>
 <dd>Faz com que a ponta da caneta se mova de volta para o início do subcaminho atual. Ele tenta traçar uma linha reta do ponto atual ao início. Se o desenho já foi fechado ou tem apenas um ponto, este método não faz nada.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.moveTo()")}}</dt>
 <dd>Move o ponto inicial de um novo subcaminho para as coordenadas (x, y).</dd>
 <dt>{{domxref("CanvasRenderingContext2D.lineTo()")}}</dt>
 <dd>Conecta o último ponto do caminho atual com as coordenadas (x, y) com linha reta.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.bezierCurveTo()")}}</dt>
 <dd>Adiciona uma curva de Bézier ao caminho atual.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.quadraticCurveTo()")}}</dt>
 <dd>Adiciona uma curva de Bézier quadrática ao caminho atual.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.arc()")}}</dt>
 <dd>Adiciona um arco circular ao caminho atual.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.arcTo()")}}</dt>
 <dd>Adiciona um arco no caminho atual com os pontos de controle e raio fornecidos, conectado ao ponto anterior por uma linha reta.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.ellipse()")}}</dt>
 <dd>Adiciona um arco elíptico ao caminho atual.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.rect()")}}</dt>
 <dd>Cria um caminho de retângulo na posição (x, y) com o tamanho determinado por <em>width</em> e <em>height</em>.</dd>
</dl>

<h2 id="Drawing_paths">Drawing paths</h2>

<dl>
 <dt>{{domxref("CanvasRenderingContext2D.fill()")}}</dt>
 <dd>Fills the subpaths with the current fill style.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.stroke()")}}</dt>
 <dd>Strokes the subpaths with the current stroke style.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.drawFocusIfNeeded()")}}</dt>
 <dd>If a given element is focused, this method draws a focus ring around the current path.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.scrollPathIntoView()")}}</dt>
 <dd>Scrolls the current path or a given path into the view.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.clip()")}}</dt>
 <dd>Creates a clipping path from the current sub-paths. Everything drawn after <code>clip()</code> is called appears inside the clipping path only. For an example, see <a href="/en-US/docs/Web/API/Canvas_API/Tutorial/Compositing" title="Clipping paths">Clipping paths</a> in the Canvas tutorial.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.isPointInPath()")}}</dt>
 <dd>Reports whether or not the specified point is contained in the current path.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.isPointInStroke()")}}</dt>
 <dd>Reports whether or not the specified point is inside the area contained by the stroking of a path.</dd>
</dl>

<h2 id="Transformações">Transformações</h2>

<p>Objects in the <code>CanvasRenderingContext2D</code> rendering context have a current transformation matrix and methods to manipulate it. The transformation matrix is applied when creating the current default path, painting text, shapes and {{domxref("Path2D")}} objects. The methods listed below remain for historical and compatibility reasons as {{domxref("SVGMatrix")}} objects are used in most parts of the API nowadays and will be used in the future instead.</p>

<dl>
 <dt>{{domxref("CanvasRenderingContext2D.currentTransform")}}</dt>
 <dd>Current transformation matrix ({{domxref("SVGMatrix")}} object).</dd>
 <dt>{{domxref("CanvasRenderingContext2D.rotate()")}}</dt>
 <dd>Adds a rotation to the transformation matrix. The angle argument represents a clockwise rotation angle and is expressed in radians.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.scale()")}}</dt>
 <dd>Adds a scaling transformation to the canvas units by x horizontally and by y vertically.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.translate()")}}</dt>
 <dd>Adds a translation transformation by moving the canvas and its origin x horzontally and y vertically on the grid.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.transform()")}}</dt>
 <dd>Multiplies the current transformation matrix with the matrix described by its arguments.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.setTransform()")}}</dt>
 <dd>Resets the current transform to the identity matrix, and then invokes the <code>transform()</code> method with the same arguments.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.resetTransform()")}} {{experimental_inline}}</dt>
 <dd>Resets the current transform by the identity matrix.</dd>
</dl>

<h2 id="Compositing">Compositing</h2>

<dl>
 <dt>{{domxref("CanvasRenderingContext2D.globalAlpha")}}</dt>
 <dd>Alpha value that is applied to shapes and images before they are composited onto the canvas. Default <code>1.0</code> (opaque).</dd>
 <dt>{{domxref("CanvasRenderingContext2D.globalCompositeOperation")}}</dt>
 <dd>With <code>globalAlpha</code> applied this sets how shapes and images are drawn onto the existing bitmap.</dd>
</dl>

<h2 id="Desenhando_imagens">Desenhando imagens</h2>

<dl>
 <dt>{{domxref("CanvasRenderingContext2D.drawImage()")}}</dt>
 <dd>Draws the specified image. This method is available in multiple formats, providing a great deal of flexibility in its use.</dd>
</dl>

<h2 id="Manipulação_de_pixels">Manipulação de pixels</h2>

<p>See also the {{domxref("ImageData")}} object.</p>

<dl>
 <dt>{{domxref("CanvasRenderingContext2D.createImageData()")}}</dt>
 <dd>Creates a new, blank {{domxref("ImageData")}} object with the specified dimensions. All of the pixels in the new object are transparent black.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.getImageData()")}}</dt>
 <dd>Returns an {{domxref("ImageData")}} object representing the underlying pixel data for the area of the canvas denoted by the rectangle which starts at <em>(sx, sy)</em> and has an <em>sw</em> width and <em>sh</em> height.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.putImageData()")}}</dt>
 <dd>Paints data from the given {{domxref("ImageData")}} object onto the bitmap. If a dirty rectangle is provided, only the pixels from that rectangle are painted.</dd>
</dl>

<h2 id="Image_smoothing">Image smoothing</h2>

<dl>
 <dt>{{domxref("CanvasRenderingContext2D.imageSmoothingEnabled")}} {{experimental_inline}}</dt>
 <dd>Image smoothing mode; if disabled, images will not be smoothed if scaled.</dd>
</dl>

<h2 id="The_canvas_state">The canvas state</h2>

<p>The <code>CanvasRenderingContext2D</code> rendering context contains a variety of drawing style states (attributes for line styles, fill styles, shadow styles, text styles). The following methods help you to work with that state:</p>

<dl>
 <dt>{{domxref("CanvasRenderingContext2D.save()")}}</dt>
 <dd>Saves the current drawing style state using a stack so you can revert any change you make to it using <code>restore()</code>.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.restore()")}}</dt>
 <dd>Restores the drawing style state to the last element on the 'state stack' saved by <code>save()</code>.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.canvas")}}</dt>
 <dd>A read-only back-reference to the {{domxref("HTMLCanvasElement")}}. Might be {{jsxref("null")}} if it is not associated with a {{HTMLElement("canvas")}} element.</dd>
</dl>

<h2 id="Hit_regions">Hit regions</h2>

<dl>
 <dt>{{domxref("CanvasRenderingContext2D.addHitRegion()")}} {{experimental_inline}}</dt>
 <dd>Adds a hit region to the canvas.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.removeHitRegion()")}} {{experimental_inline}}</dt>
 <dd>Removes the hit region with the specified <code>id</code> from the canvas.</dd>
 <dt>{{domxref("CanvasRenderingContext2D.clearHitRegions()")}} {{experimental_inline}}</dt>
 <dd>Removes all hit regions from the canvas.</dd>
</dl>

<h2 id="Non-standard_APIs">Non-standard APIs</h2>

<h3 id="Blink_and_WebKit">Blink and WebKit</h3>

<p>Most of these APIs are <a href="https://code.google.com/p/chromium/issues/detail?id=363198">deprecated and will be removed in the future</a>.</p>

<dl>
 <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.clearShadow()</code></dt>
 <dd>Removes all shadow settings like {{domxref("CanvasRenderingContext2D.shadowColor")}} and {{domxref("CanvasRenderingContext2D.shadowBlur")}}.</dd>
 <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.drawImageFromRect()</code></dt>
 <dd>This is redundant with an equivalent overload of <code>drawImage</code>.</dd>
 <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.setAlpha()</code></dt>
 <dd>Use {{domxref("CanvasRenderingContext2D.globalAlpha")}} instead.</dd>
 <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.setCompositeOperation()</code></dt>
 <dd>Use {{domxref("CanvasRenderingContext2D.globalCompositeOperation")}} instead.</dd>
 <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.setLineWidth()</code></dt>
 <dd>Use {{domxref("CanvasRenderingContext2D.lineWidth")}} instead.</dd>
 <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.setLineJoin()</code></dt>
 <dd>Use {{domxref("CanvasRenderingContext2D.lineJoin")}} instead.</dd>
 <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.setLineCap()</code></dt>
 <dd>Use {{domxref("CanvasRenderingContext2D.lineCap")}} instead.</dd>
 <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.setMiterLimit()</code></dt>
 <dd>Use {{domxref("CanvasRenderingContext2D.miterLimit")}} instead.</dd>
 <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.setStrokeColor()</code></dt>
 <dd>Use {{domxref("CanvasRenderingContext2D.strokeStyle")}} instead.</dd>
 <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.setFillColor()</code></dt>
 <dd>Use {{domxref("CanvasRenderingContext2D.fillStyle")}} instead.</dd>
 <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.setShadow()</code></dt>
 <dd>Use {{domxref("CanvasRenderingContext2D.shadowColor")}} and {{domxref("CanvasRenderingContext2D.shadowBlur")}} instead.</dd>
 <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.webkitLineDash</code></dt>
 <dd>Use {{domxref("CanvasRenderingContext2D.getLineDash()")}} and {{domxref("CanvasRenderingContext2D.setLineDash()")}} instead.</dd>
 <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.webkitLineDashOffset</code></dt>
 <dd>Use {{domxref("CanvasRenderingContext2D.lineDashOffset")}} instead.</dd>
 <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.webkitImageSmoothingEnabled</code></dt>
 <dd>Use {{domxref("CanvasRenderingContext2D.imageSmoothingEnabled")}} instead.</dd>
</dl>

<h3 id="Blink_only">Blink only</h3>

<dl>
 <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.getContextAttributes()</code></dt>
 <dd>Inspired by the same <code>WebGLRenderingContext</code> method it returns an <code>Canvas2DContextAttributes</code> object that contains the attributes "storage" to indicate which storage is used ("persistent" by default) and the attribute "alpha" (<code>true</code> by default) to indicate that transparency is used in the canvas.</dd>
 <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.isContextLost()</code></dt>
 <dd>Inspired by the same <code>WebGLRenderingContext</code> method it returns <code>true</code> if the Canvas context has been lost, or <code>false</code> if not.</dd>
</dl>

<h3 id="WebKit_only">WebKit only</h3>

<dl>
 <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.webkitBackingStorePixelRatio</code></dt>
 <dd>The backing store size in relation to the canvas element. See <a href="http://www.html5rocks.com/en/tutorials/canvas/hidpi/">High DPI Canvas</a>.</dd>
 <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.webkitGetImageDataHD</code></dt>
 <dd>Intended for HD backing stores, but removed from canvas specifications.</dd>
 <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.webkitPutImageDataHD</code></dt>
 <dd>Intended for HD backing stores, but removed from canvas specifications.</dd>
</dl>

<dl>
</dl>

<h3 id="Gecko_only">Gecko only</h3>

<dl>
 <dt>{{non-standard_inline}} {{domxref("CanvasRenderingContext2D.filter")}}</dt>
 <dd>CSS and SVG filters as Canvas APIs. Likely to be standardized in a new version of the specification.</dd>
</dl>

<h4 id="Prefixed_APIs">Prefixed APIs</h4>

<dl>
 <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.mozCurrentTransform</code></dt>
 <dd>Sets or gets the current transformation matrix, see {{domxref("CanvasRenderingContext2D.currentTransform")}}{{ gecko_minversion_inline("7.0") }}</dd>
 <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.mozCurrentTransformInverse</code></dt>
 <dd>Sets or gets the current inversed transformation matrix.  {{ gecko_minversion_inline("7.0") }}</dd>
 <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.mozFillRule</code></dt>
 <dd>The <a class="external" href="http://cairographics.org/manual/cairo-cairo-t.html#cairo-fill-rule-t" title="http://cairographics.org/manual/cairo-cairo-t.html#cairo-fill-rule-t">fill rule</a> to use. This must be one of <code>evenodd</code> or <code>nonzero</code> (default).</dd>
 <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.mozImageSmoothingEnabled</code></dt>
 <dd>See {{domxref("CanvasRenderingContext2D.imageSmoothingEnabled")}}.</dd>
 <dt>{{non-standard_inline}} {{deprecated_inline}} <code>CanvasRenderingContext2D.mozDash</code></dt>
 <dd>An array which specifies the lengths of alternating dashes and gaps {{ gecko_minversion_inline("7.0") }}. Use {{domxref("CanvasRenderingContext2D.getLineDash()")}} and {{domxref("CanvasRenderingContext2D.setLineDash()")}} instead.</dd>
 <dt>{{non-standard_inline}} {{deprecated_inline}} <code>CanvasRenderingContext2D.mozDashOffset</code></dt>
 <dd>Specifies where to start a dash array on a line. {{ gecko_minversion_inline("7.0") }}. Use {{domxref("CanvasRenderingContext2D.lineDashOffset")}} instead.</dd>
 <dt>{{non-standard_inline}} {{deprecated_inline}} <code>CanvasRenderingContext2D.mozTextStyle</code></dt>
 <dd>Introduced in in Gecko 1.9, deprecated in favor of the {{domxref("CanvasRenderingContext2D.font")}} property.</dd>
 <dt>{{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.mozDrawText()</code></dt>
 <dd>This method was introduced in Gecko 1.9 and is removed starting with Gecko 7.0. Use {{domxref("CanvasRenderingContext2D.strokeText()")}} or {{domxref("CanvasRenderingContext2D.fillText()")}} instead.</dd>
 <dt>{{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.mozMeasureText()</code></dt>
 <dd>This method was introduced in Gecko 1.9 and is unimplemented starting with Gecko 7.0. Use {{domxref("CanvasRenderingContext2D.measureText()")}} instead.</dd>
 <dt>{{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.mozPathText()</code></dt>
 <dd>This method was introduced in Gecko 1.9 and is removed starting with Gecko 7.0.</dd>
 <dt>{{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.mozTextAlongPath()</code></dt>
 <dd>This method was introduced in Gecko 1.9 and is removed starting with Gecko 7.0.</dd>
</dl>

<h4 id="Internal_APIs_chrome-context_only">Internal APIs (chrome-context only)</h4>

<dl>
 <dt>{{non-standard_inline}} {{domxref("CanvasRenderingContext2D.asyncDrawXULElement()")}}</dt>
 <dd>Renders a region of a XUL element into the <code>canvas</code>.</dd>
 <dt>{{non-standard_inline}} {{domxref("CanvasRenderingContext2D.drawWindow()")}}</dt>
 <dd>Renders a region of a window into the <code>canvas</code>. The contents of the window's viewport are rendered, ignoring viewport clipping and scrolling.</dd>
 <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.demote()</code></dt>
 <dd>This causes a context that is currently using a hardware-accelerated backend to fallback to a software one. All state should be preserved.</dd>
</dl>

<h3 id="Internet_Explorer">Internet Explorer</h3>

<dl>
 <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.msFillRule</code></dt>
 <dd>The <a class="external" href="http://cairographics.org/manual/cairo-cairo-t.html#cairo-fill-rule-t" title="http://cairographics.org/manual/cairo-cairo-t.html#cairo-fill-rule-t">fill rule</a> to use. This must be one of <code>evenodd</code> or <code>nonzero</code> (default).</dd>
</dl>

<h2 id="Especificações">Especificações</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('HTML WHATWG', "scripting.html#2dcontext:canvasrenderingcontext2d", "CanvasRenderingContext2D")}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td></td>
  </tr>
 </tbody>
</table>

<h2 id="Compatibilidade_do_Navegador">Compatibilidade do Navegador</h2>

<div>{{CompatibilityTable}}</div>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatChrome("1")}}</td>
   <td>{{CompatGeckoDesktop("1.8")}}</td>
   <td>{{CompatIE("9")}}</td>
   <td>{{CompatOpera("9")}}</td>
   <td>{{CompatSafari("2")}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Chrome for Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="Compatibility_notes">Compatibility notes</h2>

<ul>
 <li>Starting with Gecko 5.0 {{geckoRelease("5.0")}}, specifying invalid values are now silently ignored for the following methods and properties: <code>translate()</code>, <code>transform()</code>, <code>rotate(), </code><code>scale(),</code> <code>rect()</code>, <code>clearRect()</code>, <code>fillRect()</code>, <code>strokeRect()</code>, <code>lineTo()</code>, <code>moveTo()</code>, <code>quadraticCurveTo()</code>, <code>arc()</code>, <code>shadowOffsetX</code>, <code>shadowOffsetY</code><code>shadowBlur</code>.</li>
</ul>

<h2 id="Veja_também">Veja também</h2>

<ul>
 <li>{{domxref("HTMLCanvasElement")}}</li>
</ul>