Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
274 views
in Technique[技术] by (71.8m points)

javascript - 将HTML Canvas捕获为gif / jpg / png / pdf吗?(Capture HTML Canvas as gif/jpg/png/pdf?)

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

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

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

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

  ask by Parand translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Oops.

(哎呀。)

Original answer was specific to a similar question.

(原始答案是针对类似问题的。)

This has been revised:

(对此进行了修订:)

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

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

(使用IMG中的值,您可以将其写为新图像,如下所示:)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...