本文介绍了将 HTML Canvas 捕获为 gif/jpg/png/pdf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将 html 画布中显示的内容捕获或打印为图像或 pdf?

Is it possible to capture or print what's displayed in an html canvas as an image or pdf?

我想通过画布生成图像,并能够从该图像生成 png.

I'd like to generate an image via canvas, and be able to generate a png from that image.

推荐答案

糟糕.原始答案是针对类似问题的.这已被修改:

Oops. Original answer was specific to a similar question. This has been revised:

var canvas = document.getElementById("mycanvas");
var img    = canvas.toDataURL("image/png");

使用 IMG 中的值,您可以像这样将其写为新图像:

with the value in IMG you can write it out as a new Image like so:

document.write('<img src="'+img+'"/>');

这篇关于将 HTML Canvas 捕获为 gif/jpg/png/pdf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 00:38