编程语言
首页 > 编程语言> > javascript-使用画布创建元素的位图副本

javascript-使用画布创建元素的位图副本

作者:互联网

我为客户端创建了一个简单的页面布局程序,并希望提供页面的缩略图视图,例如InDesign中的页面调色板.是否可以使用HTML5 canvas元素创建单个元素的副本.

例如,每个页面都是文章标签.我想使用画布复制此文章并将其减少到10%,然后将其绘制到屏幕上.

解决方法:

canvas规范中没有当前的方法来捕获页面部分的快照. Firefox使用称为drawWindow()的方法扩展canvas元素,该方法接受要拍照的区域的坐标和尺寸.但是,由于安全方面的考虑,该方法仅适用于以chrome级权限运行的脚本.代码中对方法的注释表明,将来可能会更改:

// We can't allow web apps to call this until we fix at least the
// following potential security issues:
// -- rendering cross-domain IFRAMEs and then extracting the results
// -- rendering the user's theme and then extracting the results
// -- rendering native anonymous content (e.g., file input paths;
// scrollbars should be allowed)

http://mxr.mozilla.org/mozilla/source/content/canvas/src/nsCanvasRenderingContext2D.cpp#2352

标签:html5,canvas,thumbnails,javascript
来源: https://codeday.me/bug/20191209/2097036.html