显示图像的画布从一个画布到另一个使用画布的base64 [英] Display canvas image from one canvas to another canvas using base64

查看:561
本文介绍了显示图像的画布从一个画布到另一个使用画布的base64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如。 新变种= canvas.toDataURL(图像/ PNG);

我要为Base64就是在这个新的变量present要显示成是present第二canvas元素。不过,这并不使用drawImage方法显示的base64形象。
它的工作原理,如果我用说 image.png

I want the base64 that is present in this new variable to be displayed into 2nd canvas element that is present. But it does not display the base64 image using drawimage method. It works if I use say image.png

推荐答案

您不应该使用的base64复制的画布。您可以将源画布传递到目标画布'上下文方法的drawImage。

You shouldn't use base64 to copy the canvas. You can pass the source canvas into the destination canvas' context method, drawImage.

否则,你将遭受严重的性能损失。见我jsperf测试在 http://jsperf.com/copying-a-canvas-element

Otherwise you will suffer a serious performance hit. See my jsperf test at http://jsperf.com/copying-a-canvas-element.

的drawImage()将接受画布,以及一个图片对象。

drawImage() will accept a Canvas as well as an Image object.

试试这个:

//grab the context from your destination canvas
var destCtx = destinationCanvas.getContext('2d');

//call its drawImage() function passing it the source canvas directly
destCtx.drawImage(sourceCanvas, 0, 0);

这篇关于显示图像的画布从一个画布到另一个使用画布的base64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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