aboutsummaryrefslogtreecommitdiff
path: root/files/pt-br/web/api/htmlcanvaselement
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:42:52 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:42:52 -0500
commit074785cea106179cb3305637055ab0a009ca74f2 (patch)
treee6ae371cccd642aa2b67f39752a2cdf1fd4eb040 /files/pt-br/web/api/htmlcanvaselement
parentda78a9e329e272dedb2400b79a3bdeebff387d47 (diff)
downloadtranslated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.gz
translated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.bz2
translated-content-074785cea106179cb3305637055ab0a009ca74f2.zip
initial commit
Diffstat (limited to 'files/pt-br/web/api/htmlcanvaselement')
-rw-r--r--files/pt-br/web/api/htmlcanvaselement/getcontext/index.html292
-rw-r--r--files/pt-br/web/api/htmlcanvaselement/height/index.html79
-rw-r--r--files/pt-br/web/api/htmlcanvaselement/index.html264
-rw-r--r--files/pt-br/web/api/htmlcanvaselement/todataurl/index.html157
4 files changed, 792 insertions, 0 deletions
diff --git a/files/pt-br/web/api/htmlcanvaselement/getcontext/index.html b/files/pt-br/web/api/htmlcanvaselement/getcontext/index.html
new file mode 100644
index 0000000000..c50cd97abb
--- /dev/null
+++ b/files/pt-br/web/api/htmlcanvaselement/getcontext/index.html
@@ -0,0 +1,292 @@
+---
+title: HTMLCanvasElement.getContext()
+slug: Web/API/HTMLCanvasElement/getContext
+tags:
+ - API
+ - Canvas
+ - HTMLCanvasElement
+ - Referencia
+ - metodo
+translation_of: Web/API/HTMLCanvasElement/getContext
+---
+<div>{{APIRef("Canvas API")}}</div>
+
+<p>O metodo <strong><code>HTMLCanvasElement.getContext()</code></strong> retorna um contexto de desenho no canvas, ou {{jsxref("null")}} se o contexto identificado não é suportado.</p>
+
+<h2 id="Syntax">Syntax</h2>
+
+<pre class="syntaxbox"><var><em>canvas</em>.getContext(<em>contextType, contextAttributes</em>);</var>
+</pre>
+
+<h3 id="Parametros">Parametros</h3>
+
+<dl>
+ <dt>contextType</dt>
+ <dd>É um {{domxref("DOMString")}} contendo o contexto identificador definindo o contexto de desenho associado ao canvas.        Os valores possiveis são:
+ <ul>
+ <li><code>"2d"</code>, levando a criação de um objeto {{domxref("CanvasRenderingContext2D")}} representando uma  renderização bidimensional.</li>
+ <li><code>"webgl"</code> (or <code>"experimental-webgl"</code>) que criará um objeto {{domxref("WebGLRenderingContext")}} representando uma renderização tridimensional. Esse contexto está disponivel somente em browsers que implementam <a href="https://developer.mozilla.org/en-US/docs/Web/WebGL">WebGL</a> versão 1 (OpenGL ES 2.0).</li>
+ <li><code>"webgl2"</code> que criará um objeto {{domxref("WebGL2RenderingContext")}} representando uma renderização tridimensional. Esse contexto está disponivel somente em browsers que implementam <a href="https://developer.mozilla.org/en-US/docs/Web/WebGL">WebGL</a> versão 2 (OpenGL ES 3.0). {{experimental_inline}}</li>
+ <li><code>"bitmaprenderer"</code> que criará um  {{domxref("ImageBitmapRenderingContext")}} que apenas provê a funcionalidade de substituir o conteúdo do canvas pelo de um {{domxref("ImageBitmap")}}.</li>
+ </ul>
+
+ <div class="note">
+ <p><strong>Note</strong>: O identificador "<code>experimental-webgl</code>" é usado em novas implementações do WebGL. Essas implementações ou ainda não passaram nos casos de teste, ou os drivers gráficos na plataforma ainda não estão estáveis. O <a href="https://www.khronos.org/">Khronos Group</a> certifica as implementações do WebGL sob certas <a href="https://www.khronos.org/registry/webgl/sdk/tests/CONFORMANCE_RULES.txt">regas de conformidade</a>.</p>
+ </div>
+ </dd>
+ <dt><code>contextAttributes</code></dt>
+ <dd>
+ <p>Você pode usar alguns atributos de contexto quando criar o seu contexto de renderização, por exemplo:</p>
+
+ <pre class="brush: js">canvas.getContext('webgl',
+ { antialias: false,
+ depth: false });</pre>
+ Atributos de contexto 2d:
+
+ <ul>
+ <li><strong><code>alpha</code></strong>: Boleano que indica se o canvas contém um canal alfa. Se definido como <code>false</code>, o browser saberá que o resultado será sempre opaco, o que pode acelerar o desenho de conteudo transparente e imagens.</li>
+ <li>{{non-standard_inline}} (Gecko only) <strong><code>willReadFrequently</code></strong>: Boleano que indica quando uma série de operações read-back estão planejadas. Isso forçará o uso de renderização 2D no canvas via software (ao invés de utilizar GPU) o que pode salvar memoria quando {{domxref("CanvasRenderingContext2D.getImageData", "getImageData()")}} for chamado frequentemente. Essa opção está disponivel somente, se a flag <code>gfx.canvas.willReadFrequently.enable</code> está definida como <code>true</code> (o que, por padrão, é o caso do B2G/Firefox OS apenas).</li>
+ <li>{{non-standard_inline}} (Blink only) <strong><code>storage</code></strong>: String que indica qual storage é usado ("persistent" por padrão).</li>
+ </ul>
+ Atributos de contexto WebGL:
+
+ <ul>
+ <li><strong><code>alpha</code></strong>: Boleano que indica se o canvas contém um buffer alfa.</li>
+ <li><strong><code>depth</code></strong>: Boleano que indica que o buffer do desenho tem um buffer de profundidade de pelo menos 16 bits.</li>
+ <li><strong><code>stencil</code></strong>: Boleano que indica que o buffer do desenho tem um buffer de stencil de pelo menos 8 bits.</li>
+ <li><strong><code>antialias</code></strong>: Boleano que indica se deve realizar o anti-aliasing ou não.</li>
+ <li><strong><code>premultipliedAlpha</code></strong>: Boleano que indica se o compositor da página vai assumir que o buffer do desenho contendo cores com alfa pré-multiplicado.</li>
+ <li><strong><code>preserveDrawingBuffer</code></strong>: Se o valor é <code>true</code> os buffers não serão limpos e preservarão seus valores até serem limpos ou subrescritos pelo autor.</li>
+ <li>
+ <p><code><strong>failIfMajorPerformanceCaveat</strong></code>: Boleano que indica se um contexto será criado se a performance do sistema for baixa.</p>
+ </li>
+ </ul>
+ </dd>
+</dl>
+
+<h3 id="Return_value">Return value</h3>
+
+<p>Um {{domxref("RenderingContext")}} que pode ser:</p>
+
+<ul>
+ <li>{{domxref("CanvasRenderingContext2D")}} para <code>"2d"</code>,</li>
+ <li>{{domxref("WebGLRenderingContext")}} para <code>"webgl"</code> e <code>"experimental-webgl"</code>,</li>
+ <li>{{domxref("WebGL2RenderingContext")}} para <code>"webgl2"</code> ou</li>
+ <li>{{domxref("ImageBitmapRenderingContext")}} para <code>"bitmaprenderer"</code>.</li>
+</ul>
+
+<p>Se o <em>contextType</em> não bater com um possivel contexto de desenho,<code>null</code> é retornado.</p>
+
+<h2 id="Examples">Examples</h2>
+
+<p>Dado este elemento {{HTMLElement("canvas")}}:</p>
+
+<pre class="brush: html">&lt;canvas id="canvas" width="300" height="300"&gt;&lt;/canvas&gt;
+</pre>
+
+<p>Você pega um contexto <code>2d</code> do canvas com o código a seguir:</p>
+
+<pre class="brush: js">var canvas = document.getElementById('canvas');
+var ctx = canvas.getContext('2d');
+console.log(ctx); // CanvasRenderingContext2D { ... }
+</pre>
+
+<p>Agora você tem <a href="/en-US/docs/Web/API/CanvasRenderingContext2D">contexto de renderização 2d</a> para o canvas e você pode desenhar nele.</p>
+
+<h2 id="Specifications">Specifications</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#dom-canvas-getcontext", "HTMLCanvasElement.getContext")}}</td>
+ <td>{{Spec2('HTML WHATWG')}}</td>
+ <td>Nenhuma mudança desde o ultimo snapshot, {{SpecName('HTML5 W3C')}}</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML5.1', "scripting-1.html#dom-canvas-getcontext", "HTMLCanvasElement.getContext")}}</td>
+ <td>{{Spec2('HTML5.1')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML5 W3C', "scripting-1.html#dom-canvas-getcontext", "HTMLCanvasElement.getContext")}}</td>
+ <td>{{Spec2('HTML5 W3C')}}</td>
+ <td>Snapshot do {{SpecName('HTML WHATWG')}} contendo a definição inicial.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+<p>{{CompatibilityTable}}</p>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Edge</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>Basic support (<code>2d</code> context)</td>
+ <td>{{CompatChrome(4)}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatGeckoDesktop("1.9.2")}}</td>
+ <td>{{CompatIE(9)}}</td>
+ <td>{{CompatOpera(9)}}</td>
+ <td>{{CompatSafari(3.1)}}</td>
+ </tr>
+ <tr>
+ <td><code>webgl</code> context</td>
+ <td>{{CompatChrome(9)}}<sup>[1]</sup><br>
+ {{CompatChrome(33)}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatGeckoDesktop('1.9.2')}}<sup>[1]</sup><br>
+ {{CompatGeckoDesktop('24')}}</td>
+ <td>11.0<sup>[2]</sup></td>
+ <td>9.0<sup>[3]</sup></td>
+ <td>5.1<sup>[2]</sup></td>
+ </tr>
+ <tr>
+ <td><code>webgl2</code> context </td>
+ <td>{{CompatChrome(56)}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatGeckoDesktop('25')}}<sup>[4]</sup></td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ <tr>
+ <td>2d <code>alpha</code> context attribute</td>
+ <td>32</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatGeckoDesktop(30)}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ <tr>
+ <td>
+ <p><code>failIfMajorPerformanceCaveat</code> attribute</p>
+ </td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatGeckoDesktop(41)}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ <tr>
+ <td>bitmaprenderer context</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatGeckoDesktop(46)}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</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>Edge</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Basic support (<code>2d</code> context)</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatGeckoMobile("1.9.2")}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ </tr>
+ <tr>
+ <td><code>webgl</code> context</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}<sup>[2]</sup></td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ <tr>
+ <td><code>webgl2</code> context </td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ <tr>
+ <td>2d <code>alpha</code> context attribute</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatGeckoMobile(30)}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ <tr>
+ <td><code>failIfMajorPerformanceCaveat</code> attribute</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatGeckoMobile(41)}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ <tr>
+ <td>bitmaprenderer context</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatGeckoMobile(46)}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<p>[1] Chrome 9 e Gecko 1.9.2 inicialmente implementaram isso como um <code>experimental-webgl</code>. Desde o Chrome 33 e Gecko 24 é implementado como definido pelo padrão: <code>webgl</code>.</p>
+
+<p>[2] Internet Explorer 11, WebKit 5.1 e Firefox Mobile implementaram isso como um <code>experimental-webgl</code>.</p>
+
+<p>[3] Opera 9 implementou isso como um <code>experimental-webgl</code>, ativado nas preferencias do usuario, na versão 15.0 a preferencia de usuario foi removida.</p>
+
+<p>[4] Gecko 25 implementou isso como um "<code>experimental-webgl2</code>" ativado na preferencia do usuario <code>webgl.enable-prototype-webgl2</code>. Apartir do Gecko 42, a string "<code>webgl2</code>"é usada na mesma configuração e "<code>experimental-webgl2</code>" não é mais aceito.</p>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li>A definição de interface, {{domxref("HTMLCanvasElement")}}.</li>
+ <li>{{domxref("OffscreenCanvas.getContext()")}}</li>
+ <li>Contextos de renderização disponiveis: {{domxref("CanvasRenderingContext2D")}}, {{domxref("WebGLRenderingContext")}} and {{domxref("WebGL2RenderingContext")}} and {{domxref("ImageBitmapRenderingContext")}}.</li>
+</ul>
diff --git a/files/pt-br/web/api/htmlcanvaselement/height/index.html b/files/pt-br/web/api/htmlcanvaselement/height/index.html
new file mode 100644
index 0000000000..fd737da382
--- /dev/null
+++ b/files/pt-br/web/api/htmlcanvaselement/height/index.html
@@ -0,0 +1,79 @@
+---
+title: HTMLCanvasElement.height
+slug: Web/API/HTMLCanvasElement/height
+tags:
+ - API
+ - Canvas
+ - HTMLCanvasElement
+ - Propriedade
+ - altura
+translation_of: Web/API/HTMLCanvasElement/height
+---
+<div>
+<div>
+<div>{{APIRef("Canvas API")}}</div>
+</div>
+</div>
+
+<p>A propriedade <strong><code><span>HTMLCanvasElement.height</span></code></strong> é um <code>inteiro</code> positivo que reflete o atributo {{htmlattrxref("height", "canvas")}} do elemento HTML {{HTMLElement("canvas")}} interpretado em pixels no CSS. Quando o atributo não é especificado, ou se for definido como um valor inválido, como um <code>inteiro</code> negativo, o valor padrão de <code>150</code> será usado.</p>
+
+<p>Essa é uma de duas propriedades, que controla o tamanho do canvas, sendo a outra {{domxref("HTMLCanvasElement.width")}}.</p>
+
+<h2 id="Syntax" name="Syntax">Sintaxe</h2>
+
+<pre class="syntaxbox"><var>var <em>pxl</em> = <em>canvas</em></var>.height;
+<em>canvas</em>.height = <em>pxl</em>;
+</pre>
+
+<h2 id="Exemplos">Exemplos</h2>
+
+<p>Dado este elemento {{HTMLElement("canvas")}}:</p>
+
+<pre class="brush: html">&lt;canvas id="canvas" width="300" height="300"&gt;&lt;/canvas&gt;
+</pre>
+
+<p>Você pode capturar a altura do canvas com o seguinte código:</p>
+
+<pre class="brush: js">var canvas = document.getElementById('canvas');
+console.log(canvas.height); // 300
+</pre>
+
+<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#attr-canvas-height", "HTMLCanvasElement.height")}}</td>
+ <td>{{Spec2('HTML WHATWG')}}</td>
+ <td>No change since the latest snapshot, {{SpecName('HTML5 W3C')}}</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML5.1', "scripting-1.html#attr-canvas-height", "HTMLCanvasElement.height")}}</td>
+ <td>{{Spec2('HTML5.1')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML5 W3C', "scripting-1.html#attr-canvas-height", "HTMLCanvasElement.height")}}</td>
+ <td>{{Spec2('HTML5 W3C')}}</td>
+ <td>Snapshot of the {{SpecName('HTML WHATWG')}} containing the initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Compatibilidade_entre_os_browsers">Compatibilidade entre os browsers</h2>
+
+
+
+<p>{{Compat("api.HTMLCanvasElement.height")}}</p>
+
+<h2 id="See_Also" name="See_Also">Veja também</h2>
+
+<ul>
+ <li>A interface a define, {{domxref("HTMLCanvasElement")}}.</li>
+ <li>Outra propriedade para controlar o tamanho do canvas, {{domxref("HTMLCanvasElement.width")}}.</li>
+</ul>
diff --git a/files/pt-br/web/api/htmlcanvaselement/index.html b/files/pt-br/web/api/htmlcanvaselement/index.html
new file mode 100644
index 0000000000..c2121aab9a
--- /dev/null
+++ b/files/pt-br/web/api/htmlcanvaselement/index.html
@@ -0,0 +1,264 @@
+---
+title: HTMLCanvasElement
+slug: Web/API/HTMLCanvasElement
+tags:
+ - API
+ - Canvas
+ - HTML DOM
+ - Interface
+ - NeedsTranslation
+ - Reference
+ - TopicStub
+translation_of: Web/API/HTMLCanvasElement
+---
+<div>
+<div>{{APIRef("Canvas API")}}</div>
+</div>
+
+<p>The <strong><code>HTMLCanvasElement</code></strong> interface provides properties and methods for manipulating the layout and presentation of canvas elements. The <code>HTMLCanvasElement</code> interface also inherits the properties and methods of the {{domxref("HTMLElement")}} interface.</p>
+
+<p>{{InheritanceDiagram(600, 120)}}</p>
+
+<h2 id="Properties">Properties</h2>
+
+<p><em>Inherits properties from its parent, </em><em>{{domxref("HTMLElement")}}.</em></p>
+
+<dl>
+ <dt>{{domxref("HTMLCanvasElement.height")}}</dt>
+ <dd>Is a positive <code>integer</code> reflecting the {{htmlattrxref("height", "canvas")}} HTML attribute of the {{HTMLElement("canvas")}} element interpreted in CSS pixels. When the attribute is not specified, or if it is set to an invalid value, like a negative, the default value of <code>150</code> is used.</dd>
+ <dt>{{domxref("HTMLCanvasElement.mozOpaque")}} {{non-standard_inline}}</dt>
+ <dd>Is a {{jsxref("Boolean")}} reflecting the {{htmlattrxref("moz-opaque", "canvas")}} HTML attribute of the {{HTMLElement("canvas")}} element. It lets the canvas know whether or not translucency will be a factor. If the canvas knows there's no translucency, painting performance can be optimized.</dd>
+ <dt>{{domxref("HTMLCanvasElement.width")}}</dt>
+ <dd>Is a positive <code>integer</code> reflecting the {{htmlattrxref("width", "canvas")}} HTML attribute of the {{HTMLElement("canvas")}} element interpreted in CSS pixels. When the attribute is not specified, or if it is set to an invalid value, like a negative, the default value of <code>300</code> is used.</dd>
+ <dt>{{domxref("HTMLCanvasElement.mozPrintCallback")}}{{non-standard_inline}}</dt>
+ <dd>Is a <code>function</code> that is Initially null, Web content can set this to a JavaScript function that will be called if the page is printed. This function can then redraw the canvas at a higher resolution that is suitable for the printer being used. <a href="https://blog.mozilla.org/labs/2012/09/a-new-way-to-control-printing-output/">See this blog post.</a></dd>
+</dl>
+
+<h2 id="Methods">Methods</h2>
+
+<p><em>Inherits methods from its parent, </em><em>{{domxref("HTMLElement")}}.</em></p>
+
+<dl>
+ <dt>{{domxref("HTMLCanvasElement.captureStream()")}} {{experimental_inline}}</dt>
+ <dd>Returns a {{domxref("CanvasCaptureMediaStream")}} that is a real-time video capture of the surface of the canvas.</dd>
+ <dt>{{domxref("HTMLCanvasElement.getContext()")}}</dt>
+ <dd>Returns a drawing context on the canvas, or null if the context ID is not supported. A drawing context lets you draw on the canvas. Calling getContext with <code>"2d"</code> returns a {{domxref("CanvasRenderingContext2D")}} object, whereas calling it with <code>"experimental-webgl"</code> (or <code>"webgl"</code>) returns a {{domxref("WebGLRenderingContext")}} object. This context is only available on browsers that implement <a href="/en-US/docs/Web/WebGL">WebGL</a>.</dd>
+ <dt>{{domxref("HTMLCanvasElement.toDataURL()")}}</dt>
+ <dd>Returns a data-URL containing a representation of the image in the format specified by the <code>type</code> parameter (defaults to <code>png</code>). The returned image is in a resolution of 96dpi.</dd>
+ <dt>{{domxref("HTMLCanvasElement.toBlob()")}}</dt>
+ <dd>Creates a {{domxref("Blob")}} object representing the image contained in the canvas; this file may be cached on the disk or stored in memory at the discretion of the user agent.</dd>
+ <dt>{{domxref("HTMLCanvasElement.transferControlToOffscreen()")}} {{experimental_inline}}</dt>
+ <dd>Transfers control to an {{domxref("OffscreenCanvas")}} object, either on the main thread or on a worker.</dd>
+ <dt>{{domxref("HTMLCanvasElement.mozGetAsFile()")}} {{non-standard_inline}} {{deprecated_inline}}</dt>
+ <dd>Returns a {{domxref("File")}} object representing the image contained in the canvas; this file is a memory-based file, with the specified <code>name</code>. If <code>type</code> is not specified, the image type is <code>image/png</code>.</dd>
+</dl>
+
+<h2 id="Specifications">Specifications</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('Media Capture DOM Elements', '#html-media-element-media-capture-extensions', 'HTMLCanvasElement')}}</td>
+ <td>{{Spec2('Media Capture DOM Elements')}}</td>
+ <td>Adds the method <code>captureStream()</code>.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML WHATWG', "#the-canvas-element", "HTMLCanvasElement")}}</td>
+ <td>{{Spec2('HTML WHATWG')}}</td>
+ <td>The method <code>getContext()</code> now returns a {{domxref("RenderingContext")}} rather than an opaque <code>object</code>.<br>
+ The methods <code>probablySupportsContext()</code>, <code>setContext()</code> and <code>transferControlToProxy()</code>have been added.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML5.1', "scripting-1.html#the-canvas-element", "HTMLCanvasElement")}}</td>
+ <td>{{Spec2('HTML5.1')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML5 W3C', "scripting-1.html#the-canvas-element", "HTMLCanvasElement")}}</td>
+ <td>{{Spec2('HTML5 W3C')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+<div>{{CompatibilityTable}}</div>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Edge</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>Basic support (<code>2D</code> context)</td>
+ <td>4.0</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatGeckoDesktop('1.9.2')}}</td>
+ <td>9.0</td>
+ <td>9.0 [1]</td>
+ <td>3.1</td>
+ </tr>
+ <tr>
+ <td><code>toBlob()</code></td>
+ <td>50</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatGeckoDesktop('19')}} [2]</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatNo}} (bug <a href="https://bugs.webkit.org/show_bug.cgi?id=71270">71270</a>)</td>
+ </tr>
+ <tr>
+ <td><code>probablySupportsContext()</code>,<br>
+ <code>setContext()</code>,<br>
+ <code>transferControlToProxy()</code> {{obsolete_inline}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ <tr>
+ <td><code>mozGetAsFile()</code> {{non-standard_inline}} {{deprecated_inline}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatGeckoDesktop('2')}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ <tr>
+ <td><code>captureStream()</code> {{experimental_inline}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatGeckoDesktop('41')}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ <tr>
+ <td><code>transferControlToOffscreen()</code> {{experimental_inline}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatGeckoDesktop(44)}} [3]</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</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>Edge</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Basic support (<code>2D</code> context)</td>
+ <td>2.1</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>10.0 [1]</td>
+ <td>3.2</td>
+ </tr>
+ <tr>
+ <td><code>webgl</code> context</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatVersionUnknown}} as <code>experimental-webgl</code></td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ <tr>
+ <td><code>toBlob()</code></td>
+ <td>{{CompatNo}} (bug <a href="http://crbug.com/67587">67587</a>)</td>
+ <td>50</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatGeckoMobile('18')}} [2]</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatNo}} (bug <a href="https://bugs.webkit.org/show_bug.cgi?id=71270">71270</a>)</td>
+ </tr>
+ <tr>
+ <td><code>probablySupportsContext()</code>,<br>
+ <code>setContext()</code>,<br>
+ <code>transferControlToProxy() </code>{{obsolete_inline}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ <tr>
+ <td><code>mozGetAsFile()</code> {{non-standard_inline}} {{deprecated_inline}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatGeckoMobile('2')}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ <tr>
+ <td><code>captureStream() </code>{{experimental_inline}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatGeckoMobile('41')}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ <tr>
+ <td><code>transferControlToOffscreen()</code> {{experimental_inline}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatGeckoMobile(44)}} [3]</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<p>[1] Opera Mini 5.0 and later has partial support.</p>
+
+<p>[2] Support for the third parameter, has been added in Gecko 25 only: when used with the <code>"image/jpeg"</code> type, this argument specifies the image quality.</p>
+
+<p>[3] This feature is behind a feature preference setting. In about:config, set <code>gfx.offscreencanvas.enabled</code> to <code>true</code>.</p>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li>HTML element implementing this interface: {{HTMLElement("canvas")}}.</li>
+</ul>
diff --git a/files/pt-br/web/api/htmlcanvaselement/todataurl/index.html b/files/pt-br/web/api/htmlcanvaselement/todataurl/index.html
new file mode 100644
index 0000000000..503f9cb636
--- /dev/null
+++ b/files/pt-br/web/api/htmlcanvaselement/todataurl/index.html
@@ -0,0 +1,157 @@
+---
+title: HTMLCanvasElement.toDataURL()
+slug: Web/API/HTMLCanvasElement/toDataURL
+tags:
+ - API
+ - Canvas
+ - HTMLCanvasElement
+ - Imagens
+translation_of: Web/API/HTMLCanvasElement/toDataURL
+---
+<div>
+<div>
+<div>{{APIRef("Canvas API")}}</div>
+</div>
+</div>
+
+<p>O método <strong><code>HTMLCanvasElement.toDataURL()</code></strong> retorna uma <a href="/en-US/docs/Web/HTTP/data_URIs">data URI</a>, contendo uma representação da imagem no formato especificado pelo parâmetro <code>type</code> (por padrão, esse valor é <a href="https://en.wikipedia.org/wiki/Portable_Network_Graphics">PNG</a>). A resolução da imagem retornada é de 96 dpi.</p>
+
+<ul>
+ <li>Se a altura ou largura do canvas for <code>0</code>, será retornada a string <code>"data:,"</code>.</li>
+ <li>Se o tipo solicitado não for <code>image/png</code>, mas o valor retornado começa com <code>data:image/png</code>, então o tipo da requisição não é suportado.</li>
+ <li>O Chrome também suporta o tipo <code>image/webp</code>.</li>
+</ul>
+
+<h2 id="Syntax" name="Syntax">Sintaxe</h2>
+
+<pre class="syntaxbox"><var><em>canvas</em>.toDataURL(<em>type</em>, <em>encoderOptions</em>);</var>
+</pre>
+
+<h3 id="Parâmetros">Parâmetros</h3>
+
+<dl>
+ <dt><code>type</code> {{optional_inline}}</dt>
+ <dd>Uma {{domxref("DOMString")}} indicando o formato da imagem. Por padrão, o formato definido é <code>image/png</code>.</dd>
+ <dt><code>encoderOptions</code> {{optional_inline}}</dt>
+ <dd>Um {{jsxref("Number")}} entre <code>0</code> e <code>1</code>, indicando a qualidade da imagem solicitada pelo tipo <code>image/jpeg</code> ou <code>image/webp</code>.<br>
+ Se esse argumento for outro valor que não de <code>0</code> a <code>1</code>, então o valor padrão (<code>0.92)</code> será usado. Outros valores serão ignorados.</dd>
+</dl>
+
+<h3 id="Valor_retornado">Valor retornado</h3>
+
+<p>Uma {{domxref("DOMString")}} contendo a <a href="/en-US/docs/Web/HTTP/data_URIs">data URI</a> solicitada.</p>
+
+<h2 id="Exemplos">Exemplos</h2>
+
+<p>Dado este elemento {{HTMLElement("canvas")}}:</p>
+
+<pre class="brush: html">&lt;canvas id="canvas" width="5" height="5"&gt;&lt;/canvas&gt;
+</pre>
+
+<p>Você poderá capturar a data-URL do canvas com as seguintes linhas:</p>
+
+<pre class="brush: js">var canvas = document.getElementById('canvas');
+var dataURL = canvas.toDataURL();
+console.log(dataURL);
+// "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNby
+// blAAAADElEQVQImWNgoBMAAABpAAFEI8ARAAAAAElFTkSuQmCC"
+</pre>
+
+<h3 id="Defindo_a_qualidade_de_imagens_jpeg">Defindo a qualidade de imagens jpeg</h3>
+
+<pre class="brush: js">var fullQuality = canvas.toDataURL('image/jpeg', 1.0);
+// data:image/jpeg;base64,/9j/4AAQSkZJRgABAQ...9oADAMBAAIRAxEAPwD/AD/6AP/Z"
+var mediumQuality = canvas.toDataURL('image/jpeg', 0.5);
+var lowQuality = canvas.toDataURL('image/jpeg', 0.1);
+</pre>
+
+<h3 id="Example_Dynamically_change_images" name="Example:_Dynamically_change_images">Exemplo: Alterando imagens dinamicamente</h3>
+
+<p>Você poderá utilizar esta técnica em associação com os eventos do mouse para alterar dinamicamente uma imagem (escala de cinza vs. cor, neste exemplo):</p>
+
+<h4 id="HTML">HTML</h4>
+
+<pre class="brush: html">&lt;img class="grayscale" src="myPicture.png" alt="Description of my picture" /&gt;</pre>
+
+<h4 id="JavaScript">JavaScript</h4>
+
+<pre class="brush: js;highlight:[33]">window.addEventListener('load', removeColors);
+
+function showColorImg() {
+ this.style.display = 'none';
+ this.nextSibling.style.display = 'inline';
+}
+
+function showGrayImg() {
+ this.previousSibling.style.display = 'inline';
+ this.style.display = 'none';
+}
+
+function removeColors() {
+ var aImages = document.getElementsByClassName('grayscale'),
+ nImgsLen = aImages.length,
+ oCanvas = document.createElement('canvas'),
+ oCtx = oCanvas.getContext('2d');
+ for (var nWidth, nHeight, oImgData, oGrayImg, nPixel, aPix, nPixLen, nImgId = 0; nImgId &lt; nImgsLen; nImgId++) {
+ oColorImg = aImages[nImgId];
+ nWidth = oColorImg.offsetWidth;
+ nHeight = oColorImg.offsetHeight;
+ oCanvas.width = nWidth;
+ oCanvas.height = nHeight;
+ oCtx.drawImage(oColorImg, 0, 0);
+ oImgData = oCtx.getImageData(0, 0, nWidth, nHeight);
+ aPix = oImgData.data;
+ nPixLen = aPix.length;
+ for (nPixel = 0; nPixel &lt; nPixLen; nPixel += 4) {
+ aPix[nPixel + 2] = aPix[nPixel + 1] = aPix[nPixel] = (aPix[nPixel] + aPix[nPixel + 1] + aPix[nPixel + 2]) / 3;
+ }
+ oCtx.putImageData(oImgData, 0, 0);
+ oGrayImg = new Image();
+ oGrayImg.src = oCanvas.toDataURL();
+ oGrayImg.onmouseover = showColorImg;
+ oColorImg.onmouseout = showGrayImg;
+ oCtx.clearRect(0, 0, nWidth, nHeight);
+ oColorImg.style.display = "none";
+ oColorImg.parentNode.insertBefore(oGrayImg, oColorImg);
+ }
+}</pre>
+
+<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#dom-canvas-todataurl", "HTMLCanvasElement.toDataURL")}}</td>
+ <td>{{Spec2('HTML WHATWG')}}</td>
+ <td>No change since the latest snapshot, {{SpecName('HTML5 W3C')}}</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML5.1', "scripting-1.html#dom-canvas-todataurl", "HTMLCanvasElement.toDataURL")}}</td>
+ <td>{{Spec2('HTML5.1')}}</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML5 W3C', "scripting-1.html#dom-canvas-todataurl", "HTMLCanvasElement.toDataURL")}}</td>
+ <td>{{Spec2('HTML5 W3C')}}</td>
+ <td>Snapshot of the {{SpecName('HTML WHATWG')}} containing the initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Compatibilidade_entre_navegadores">Compatibilidade entre navegadores</h2>
+
+
+
+<p>{{Compat("api.HTMLCanvasElement.toDataURL")}}</p>
+
+<h2 id="See_Also" name="See_Also">Veja também</h2>
+
+<ul>
+ <li>A interface que a define, {{domxref("HTMLCanvasElement")}}.</li>
+ <li><a href="/en-US/docs/Web/HTTP/data_URIs">Data URIs</a> na referência <a href="/en-US/docs/Web/HTTP">HTTP</a>.</li>
+</ul>