aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/mozilla/add-ons/webextensions/api/clipboard/setimagedata/index.html
diff options
context:
space:
mode:
authorFlorian Merz <me@fiji-flo.de>2021-02-11 12:56:40 +0100
committerFlorian Merz <me@fiji-flo.de>2021-02-11 12:56:40 +0100
commit310fd066e91f454b990372ffa30e803cc8120975 (patch)
treed5d900deb656a5da18e0b60d00f0db73f3a2e88e /files/zh-cn/mozilla/add-ons/webextensions/api/clipboard/setimagedata/index.html
parent8260a606c143e6b55a467edf017a56bdcd6cba7e (diff)
downloadtranslated-content-310fd066e91f454b990372ffa30e803cc8120975.tar.gz
translated-content-310fd066e91f454b990372ffa30e803cc8120975.tar.bz2
translated-content-310fd066e91f454b990372ffa30e803cc8120975.zip
unslug zh-cn: move
Diffstat (limited to 'files/zh-cn/mozilla/add-ons/webextensions/api/clipboard/setimagedata/index.html')
-rw-r--r--files/zh-cn/mozilla/add-ons/webextensions/api/clipboard/setimagedata/index.html79
1 files changed, 79 insertions, 0 deletions
diff --git a/files/zh-cn/mozilla/add-ons/webextensions/api/clipboard/setimagedata/index.html b/files/zh-cn/mozilla/add-ons/webextensions/api/clipboard/setimagedata/index.html
new file mode 100644
index 0000000000..3cdaf45b08
--- /dev/null
+++ b/files/zh-cn/mozilla/add-ons/webextensions/api/clipboard/setimagedata/index.html
@@ -0,0 +1,79 @@
+---
+title: clipboard.setImageData()
+slug: Mozilla/Add-ons/WebExtensions/API/剪切板/setImageData
+tags:
+ - API
+ - Clipboard
+ - 剪贴板
+ - 参考
+ - 拓展
+ - 方法
+translation_of: Mozilla/Add-ons/WebExtensions/API/clipboard/setImageData
+---
+<div>{{AddonSidebar()}}</div>
+
+<p>将图像复制到剪贴板。在将图像写入剪贴板之前,会对图像进行重新编码。如果图像无效,则不会修改剪贴板。</p>
+
+<p>图像被作为包含经过编码的图像的 <code><a href="/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer">ArrayBuffer</a></code> 提供。支持 JPEG 和 PNG 格式。</p>
+
+<p>基于 Chrome 的 <code><a href="https://developer.chrome.com/apps/clipboard" rel="noopener">clipboard.setImageData()</a></code> API,但存在一些差异:</p>
+
+<ul>
+ <li>Chrome API 仅适用于应用,不适用于扩展程序。</li>
+ <li>此API需要 <code>"clipboardWrite"</code> 权限,Chrome 版本需要 <code>"clipboard"</code> 权限。</li>
+ <li>Chrome 的 API 使用回调,此 API 使用 Promise。</li>
+ <li>此 API 不支持 <code>additionalItems</code> 参数。</li>
+</ul>
+
+<p>这是一个返回 <code><a href="/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a></code> 的异步函数。</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox brush:js">browser.clipboard.setImageData(<em>imageData</em>, <em>imageType</em>)
+</pre>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt><code>imageData</code></dt>
+ <dd>An <code><a href="/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer">ArrayBuffer</a></code> containing the encoded image data to copy to the clipboard.</dd>
+ <dt><code>imageType</code></dt>
+ <dd>A {{domxref("DOMString")}} indicating the type of image contained in <code>imageData</code>: <code>"png"</code> or <code>"jpeg"</code>.</dd>
+</dl>
+
+<h3 id="返回值">返回值</h3>
+
+<p>A <code><a href="/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a></code> that will be resolved with no arguments if the operation succeeded, or rejected if there was an error (for example, because the data did not represent a valid image).</p>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>
+
+<p>{{Compat("webextensions.api.clipboard.setImageData", 10)}}</p>
+
+<h2 id="示例">示例</h2>
+
+<p>Copy a remote image:</p>
+
+<pre class="brush: js" id="ct-71"><span class="quote">// requires:
+// * the host permission for "<a href="https://cdn.mdn.mozilla.net/" rel="nofollow">https://cdn.mdn.mozilla.net/</a>*"
+// * the API permission "clipboardWrite"
+
+fetch('<a href="https://cdn.mdn.mozilla.net/static/img/favicon144.png" rel="nofollow">https://cdn.mdn.mozilla.net/static/img/favicon144.png</a>')
+.then(response =&gt; response.arrayBuffer())
+.then(buffer =&gt; browser.clipboard.setImageData(buffer, 'png'));</span></pre>
+
+<p><span class="quote">Copy an image that was bundled with the extension:</span></p>
+
+<pre class="brush: js" id="ct-70">// requires <span class="quote">the API permission </span>"clipboardWrite"
+
+fetch(browser.runtime.getURL('image.png'))
+.then(response =&gt; response.arrayBuffer())
+.then(buffer =&gt; browser.clipboard.setImageData(buffer, 'png'));</pre>
+
+<p>{{WebExtExamples}}</p>
+
+<div class="note"><strong>说明</strong>
+
+<p> 此 API 基于 Chromium 的 <a href="https://developer.chrome.com/apps/clipboard"><code>chrome.clipboard</code></a> API.</p>
+</div>