如何更改使用chrome.tabs.captureVisibleTab(Chrome扩展程序)捕获的选项卡的大小

Tom*_*Tom 5 html5 google-chrome google-chrome-extension

我正在使用以下代码捕获所选标签的屏幕截图

chrome.tabs.captureVisibleTab( undefined, function( data ) { display( data ) });
Run Code Online (Sandbox Code Playgroud)

该API表示可以更改标签的大小(http://code.google.com/chrome/extensions/tabs.html#method-captureVisibleTab),但我无法弄清楚如何操作.目前所有截图都以全尺寸(1440x900)出现,但我只需要缩略图尺寸.

有谁知道如何使用这个API来做到这一点?

谢谢.

Moh*_*our 10

Chrome API实际上并未提供图片大小调整captureVisibleTab.该功能的作用基本上就是你所看到的是你从该标签获得的图像.

如果要调整该选项卡的图像大小.您可以使用HTML5 Canvas. http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html

您可以将图像加载到Canvas中,然后从该画布中调整图像大小并随意执行任何操作.您可以使用将图像放入画布上下文中drawImage

http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#images

根据drawImage的参数,您可以调整它的大小,或者您可以使用其他画布功能进行剪裁或裁剪.

然后,在完成图像大小调整后,您可以使用toDataURL它将其转换回来,以便您可以使用它或存储它.

http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#dom-canvas-todataurl