Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 746751 of ImageData

  • Revision slug: Web/API/ImageData
  • Revision title: ImageData
  • Revision id: 746751
  • Created:
  • Creator: fscholz
  • Is current revision? No
  • Comment

Revision Content

{{APIRef("Canvas API")}}

The ImageData interface represents the underlying pixel data of an area of a {{HTMLElement("canvas")}} element. It is created using the {{domxref("ImageData.ImageData", "ImageData()")}} constructor or creator methods on the {{domxref("CanvasRenderingContext2D")}} object associated with a canvas: {{domxref("CanvasRenderingContext2D.createImageData", "createImageData()")}} and {{domxref("CanvasRenderingContext2D.getImageData", "getImageData()")}}. It can also be used to set a part of the canvas by using {{domxref("CanvasRenderingContext2D.putImageData", "putImageData()")}}.

Constructors

{{domxref("ImageData.ImageData", "ImageData()")}} {{experimental_inline}}
Creates an ImageData object from a given {{jsxref("Uint8ClampedArray")}} and the size of the image it contains. If no array is given, it creates an image of a black rectangle. Note that as this is the most common way to create such an object in workers as {{domxref("CanvasRenderingContext2D.createImageData", "createImageData()")}} is not available there.

Properties

{{domxref("ImageData.data")}} {{readonlyInline}}
Is a {{jsxref("Uint8ClampedArray")}} representing a one-dimensional array containing the data in the RGBA order, with integer values between 0 and 255 (included).
{{domxref("ImageData.height")}} {{readonlyInline}}
Is an unsigned long representing the actual height, in pixels, of the ImageData.
{{domxref("ImageData.width")}} {{readonlyInline}}
Is an unsigned long representing the actual width, in pixels, of the ImageData.

Specifications

Specification Status Comment
{{SpecName('HTML WHATWG', "the-canvas-element.html#imagedata", "ImageData")}} {{Spec2('HTML WHATWG')}}  

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 4.0 {{CompatGeckoDesktop("14")}} 9.0 9.0 3.1
Support in workers {{CompatUnknown}} {{CompatGeckoDesktop("25")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
ImageData() constructor {{CompatUnknown}} {{CompatGeckoDesktop("29")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 2.1 {{CompatGeckoMobile("14")}} {{CompatUnknown}} 10.0 3.2
Support in workers {{CompatUnknown}} {{CompatGeckoMobile("25")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
ImageData() constructor {{CompatUnknown}} {{CompatGeckoMobile("29")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

See also

  • {{domxref("CanvasRenderingContext2D")}}
  • The {{HTMLElement("canvas")}} element and its associated interface, {{domxref("HTMLCanvasElement")}}.

Revision Source

<div>{{APIRef("Canvas API")}}</div>

<p>The <code><strong>ImageData</strong></code> interface represents the underlying pixel data of an area of a {{HTMLElement("canvas")}} element. It is created using the {{domxref("ImageData.ImageData", "ImageData()")}} constructor or creator methods on the {{domxref("CanvasRenderingContext2D")}} object associated with a canvas: {{domxref("CanvasRenderingContext2D.createImageData", "createImageData()")}} and {{domxref("CanvasRenderingContext2D.getImageData", "getImageData()")}}. It can also be used to set a part of the canvas by using {{domxref("CanvasRenderingContext2D.putImageData", "putImageData()")}}.</p>

<h2 id="Constructors">Constructors</h2>

<dl>
 <dt>{{domxref("ImageData.ImageData", "ImageData()")}} {{experimental_inline}}</dt>
 <dd>Creates an <code>ImageData</code> object from a given {{jsxref("Uint8ClampedArray")}} and the size of the image it contains. If no array is given, it creates an image of a black rectangle. Note that as this is the most common way to create such an object in workers as {{domxref("CanvasRenderingContext2D.createImageData", "createImageData()")}} is not available there.</dd>
</dl>

<h2 id="Properties">Properties</h2>

<dl>
 <dt>{{domxref("ImageData.data")}} {{readonlyInline}}</dt>
 <dd>Is a {{jsxref("Uint8ClampedArray")}} representing a one-dimensional array containing the data in the RGBA order, with integer values between <code>0</code> and <code>255</code> (included).</dd>
 <dt>{{domxref("ImageData.height")}} {{readonlyInline}}</dt>
 <dd>Is an <code>unsigned</code> <code>long</code> representing the actual height, in pixels, of the <code>ImageData</code>.</dd>
 <dt>{{domxref("ImageData.width")}} {{readonlyInline}}</dt>
 <dd>Is an <code>unsigned</code> <code>long</code> representing the actual width, in pixels, of the <code>ImageData</code>.</dd>
</dl>

<h2 id="Specifications" name="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('HTML WHATWG', "the-canvas-element.html#imagedata", "ImageData")}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>&nbsp;</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>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>4.0</td>
   <td>{{CompatGeckoDesktop("14")}}</td>
   <td>9.0</td>
   <td>9.0</td>
   <td>3.1</td>
  </tr>
  <tr>
   <td>Support in workers</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoDesktop("25")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>ImageData()</code> constructor</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoDesktop("29")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>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>2.1</td>
   <td>{{CompatGeckoMobile("14")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>10.0</td>
   <td>3.2</td>
  </tr>
  <tr>
   <td>Support in workers</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoMobile("25")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>ImageData()</code> constructor</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoMobile("29")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{domxref("CanvasRenderingContext2D")}}</li>
 <li>The {{HTMLElement("canvas")}} element and its associated interface, {{domxref("HTMLCanvasElement")}}.</li>
</ul>
Revert to this revision