aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/createimagebitmap
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/api/createimagebitmap')
-rw-r--r--files/zh-cn/web/api/createimagebitmap/index.html208
1 files changed, 208 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/createimagebitmap/index.html b/files/zh-cn/web/api/createimagebitmap/index.html
new file mode 100644
index 0000000000..c71c592551
--- /dev/null
+++ b/files/zh-cn/web/api/createimagebitmap/index.html
@@ -0,0 +1,208 @@
+---
+title: self.createImageBitmap()
+slug: Web/API/createImageBitmap
+translation_of: Web/API/WindowOrWorkerGlobalScope/createImageBitmap
+original_slug: Web/API/WindowOrWorkerGlobalScope/createImageBitmap
+---
+<div>{{APIRef("Canvas API")}}</div>
+
+<p><code><strong>createImageBitmap</strong></code> 方法存在 windows 和 workers 中. 它接受各种不同的图像来源, 并返回一个{{domxref("Promise")}}, resolve为{{domxref("ImageBitmap")}}. 可选地参数,图像被剪裁成自(sx,sy)且宽度为sw,高度为sh的像素的矩形。</p>
+
+<h2 id="Syntax">Syntax</h2>
+
+<pre>createImageBitmap(<em>image</em>[, options]).then(function(response) { ... });
+createImageBitmap(<em>image, sx, sy, sw, sh</em>[, options]).then(function(response) { ... });
+</pre>
+
+<h3 id="Parameters">Parameters</h3>
+
+<dl>
+ <dt><code>image</code></dt>
+ <dd>一个图像源, 可以是一个 {{HTMLElement("img")}}, SVG {{SVGElement("image")}}, {{HTMLElement("video")}}, {{HTMLElement("canvas")}}, {{domxref("HTMLImageElement")}}, {{domxref("SVGImageElement")}}, {{domxref("HTMLVideoElement")}}, {{domxref("HTMLCanvasElement")}}, {{domxref("Blob")}}, {{domxref("ImageData")}}, {{domxref("ImageBitmap")}}, 或 {{domxref("OffscreenCanvas")}} 对象.</dd>
+ <dt><code>sx</code></dt>
+ <dd>裁剪点x坐标.</dd>
+ <dt><code>sy</code></dt>
+ <dd>裁剪点y坐标.</dd>
+ <dt><code>sw</code></dt>
+ <dd>裁剪宽度,值可为负数.</dd>
+ <dt><code>sh</code></dt>
+ <dd>裁剪高度,值可为负数.</dd>
+ <dt>options {{optional_inline}}</dt>
+ <dd>为其设置选项的对象。可用的选项是:
+ <ul>
+ <li><code>imageOrientation</code>: 指示图像是按原样呈现还是垂直翻转.  <code>none</code> (默认不翻转) 或 <code>flipY</code>.</li>
+ <li><code>premultiplyAlpha</code>: 指示位图颜色通道由alpha通道预乘. 选择其一:<code>none</code>, <code>premultiply</code>, 或 <code>default</code> (默认).</li>
+ <li><code>colorSpaceConversion</code>: 指示图像是否使用色彩空间转换进行解码. <code>none</code> 或 <code>default</code> (默认). The value <code>default</code> indicates that implementation-specific behavior is used.</li>
+ <li><code>resizeWidth</code>: 指示新宽度的长整数。</li>
+ <li><code>resizeHeight</code>: 指示新高度的长整数。</li>
+ <li><code>resizeQuality</code>: 指定图像缩放算法. 选择其一<code>pixelated</code>, <code>low</code> (默认), <code>medium</code>, 或 <code>high</code>.</li>
+ </ul>
+ </dd>
+</dl>
+
+<h3 id="Return_value">Return value</h3>
+
+<p>返回一个解决ImageBitmap的{{domxref("Promise")}} ,当Promise成功时resolves接收一个包含所得到的矩形的位图数据{{domxref("ImageBitmap")}}。</p>
+
+<h2 id="Example">Example</h2>
+
+<pre class="brush: js language-js">var canvas = document.getElementById('myCanvas'),
+ctx = canvas.getContext('2d'),
+image = new Image();
+
+image.onload = function() {
+ Promise.all([
+ createImageBitmap(this, 0, 0, 32, 32),
+ createImageBitmap(this, 32, 0, 32, 32)
+ ]).then(function(sprites) {
+ ctx.drawImage(sprites[0], 0, 0);
+ ctx.drawImage(sprites[1], 32, 32);
+ });
+}
+
+image.src = 'sprites.png';
+</pre>
+
+<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', "webappapis.html#dom-createimagebitmap", "createImageBitmap")}}</td>
+ <td>{{Spec2('HTML WHATWG')}}</td>
+ <td> </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>Firefox (Gecko)</th>
+ <th>Edge</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatChrome(50)}}</td>
+ <td>
+ <p>{{CompatGeckoDesktop(42)}}<br>
+ {{CompatGeckoDesktop(52)}}<sup>[1]</sup></p>
+ </td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ <tr>
+ <td><code>options</code> parameter</td>
+ <td>{{CompatChrome(52)}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>39</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ <tr>
+ <td><code>resizeWidth</code>, <code>resizeHeight</code>, and <code>resizeQuality</code></td>
+ <td>{{CompatChrome(54)}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ <tr>
+ <td><code>SVGImageElement</code> as source image</td>
+ <td>{{CompatChrome(59)}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android Webview</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>{{CompatChrome(50)}}</td>
+ <td>{{CompatChrome(50)}}</td>
+ <td>
+ <p>{{CompatGeckomobile(42)}}<br>
+ {{CompatGeckoMobile(52)}}<sup>[1]</sup></p>
+ </td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ <tr>
+ <td><code>options</code> parameter</td>
+ <td>{{CompatChrome(52)}}</td>
+ <td>{{CompatChrome(52)}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>39</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ <tr>
+ <td><code>resizeWidth</code>, <code>resizeHeight</code>, and <code>resizeQuality</code></td>
+ <td>{{CompatChrome(54)}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td><code>SVGImageElement</code> as source image</td>
+ <td>{{CompatChrome(59)}}</td>
+ <td>{{CompatChrome(59)}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<p>[1] <code>createImageBitmap()</code> now defined on {{domxref("WindowOrWorkerGlobalScope")}} mixin.</p>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li>{{domxref("CanvasRenderingContext2D.drawImage()")}}</li>
+ <li>{{domxref("ImageData")}}</li>
+</ul>
+
+<p>
+ <audio class="hidden"> </audio>
+</p>