将HTML元素渲染到< canvas> [英] Rendering HTML elements to <canvas>

查看:120
本文介绍了将HTML元素渲染到< canvas>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在canvas中呈现一个任意的HTML元素(然后访问它的缓冲区......)。

目前,由于canvas上下文不具备呈现HTML元素的功能,因此您无法将真实的HTML呈现转换为< canvas> 本身。



有一些模拟:

html2canvas项目 http://html2canvas.hertzen.com/index.html (基本上是一个基于Javascript + canvas的HTML渲染器尝试)



HTML to SVG to < canvas> 可能取决于您的用例: $ b

https://github.com/miohtama/Krusovice/blob/master/src/tools/html2svg2canvas.js



另外,如果您使用Firefox 权限,然后将DOM窗口呈现为< canvas>



https://developer.mozilla.org/en-US/docs/HTML/Canvas/Drawing_Graphics_with_Canvas?redirectlocale=zh-CN&redirectslug=Drawing_Graphics_with_Canvas#Rendering_Web_Content_Into_A_Canvas


Is there a way to have an arbitrary HTML element rendered in a canvas (and then access its buffer...).

解决方案

You won't get real HTML rendering to <canvas> per se currently, because canvas context does not have functions to render HTML elements.

There are some emulations:

html2canvas project http://html2canvas.hertzen.com/index.html (basically a HTML renderer attempt built on Javascript + canvas)

HTML to SVG to <canvas> might be possible depending on your use case:

https://github.com/miohtama/Krusovice/blob/master/src/tools/html2svg2canvas.js

Also if you are using Firefox you can hack some extended permissions and then render a DOM window to <canvas>

https://developer.mozilla.org/en-US/docs/HTML/Canvas/Drawing_Graphics_with_Canvas?redirectlocale=en-US&redirectslug=Drawing_Graphics_with_Canvas#Rendering_Web_Content_Into_A_Canvas

这篇关于将HTML元素渲染到&lt; canvas&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆