blob: 20c5f15bc7b01c6a910005846e2c4923ff6f1d54 (
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
|
---
title: ImageData()
slug: Web/API/ImageData/ImageData
translation_of: Web/API/ImageData/ImageData
---
<p>{{APIRef("Canvas API")}}</p>
<p><code><strong>ImageData()</strong></code> 构造函数返回一个新的实例化的 <code style="font-style: normal; line-height: 1.5;">ImageData</code><span style="line-height: 1.5;"> 对象,</span><span style="line-height: 1.5;"> 此对象由给定的类型化数组和指定的宽度与高度组成。</span></p>
<p>这个构造器是创建像这种对象首选的方式。</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox">new ImageData(<em>array</em>, <em>width</em>, <em>height</em>);
<em>n</em>ew ImageData(<em>width</em>, <em>height</em>);
</pre>
<h3 id="参数">参数</h3>
<dl>
<dt><code>array </code></dt>
<dd>包含图像隐藏像素的 {{jsxref("Uint8ClampedArray")}} 数组。如果数组没有给定,指定大小的黑色矩形图像将会被创建。</dd>
<dt><code>width</code></dt>
<dd>无符号长整型(unsigned long)数值,描述图像的宽度。</dd>
<dt><span class="hidden"> </span><code>height</code></dt>
<dd> 无符号长整型(unsigned long)数值,描述图像的高度。</dd>
<dd>如果已给定数组,这个值是可选的:它将通过它的大小和给定的宽度进行推断。</dd>
</dl>
<dl>
</dl>
<h2 id="示例">示例</h2>
<pre class="brush: js language-js">var imageData = new ImageData(100, 100); // Creates a 100x100 black rectangle
// ImageData { width: 100, height: 100, data: Uint8ClampedArray[40000] }
</pre>
<h2 id="Specification" name="Specification">规范描述</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-imagedata', 'ImageData()')}}</td>
<td>{{Spec2('HTML WHATWG')}}</td>
<td>Initial definition.</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p>{{Compat("api.ImageData.ImageData")}}</p>
<h2 id="参见">参见</h2>
<ul>
<li>{{domxref("CanvasRenderingContext2D.createImageData()")}}, the creator method that can be used outside workers.</li>
</ul>
|