Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想使用 HTML5 在图像上添加文本。如何才能做到这一点?
您可以将图像加载到画布中(使用drawImage()),然后在画布上绘制文本(使用fillText())。
drawImage()
fillText()
如果您愿意,您可以使用从画布中获取图像数据toDataUrl()并将该数据发布到服务器以进行图像持久性。
toDataUrl()
如果您只需要它来实现客户端可见性,那么您有一个不使用 html5 的更简单的解决方案。只需使用绝对定位在图像上覆盖文本。