java todataurl_html2canvas 转化的 canvas 不能调用toDataURL 方法?

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

//将dom树转换为canvas

function print_body() {

var test = $('div.helloworld');

html2canvas(test, {

onrendered : function(canvas) {

document.body.appendChild(canvas);

}

});

alert(test)

//然后调用下载的方法

download_canvas(test);

}

//将canvas画板导出

function download_canvas(oCanvas) {

var bMouseIsDown = false;

//var oCanvas = document.getElementById("thecanvas");

oCanvas.onmousedown = function(e) {

bMouseIsDown = true;

iLastX = e.clientX

- oCanvas.offsetLeft

+ (window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft);

iLastY = e.clientY

- oCanvas.offsetTop

+ (window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop);

}

oCanvas.onmouseup = function() {

bMouseIsDown = false;

iLastX = -1;

iLastY = -1;

}

oCanvas.onmousemove = function(e) {

if (bMouseIsDown) {

var iX = e.clientX

- oCanvas.offsetLeft

+ (window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft);

var iY = e.clientY

- oCanvas.offsetTop

+ (window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop);

iLastX = iX;

iLastY = iY;

}

}

function showDownloadText() {

document.getElementById("buttoncontainer").style.display = "none";

document.getElementById("textdownload").style.display = "block";

}

function hideDownloadText() {

document.getElementById("buttoncontainer").style.display = "block";

document.getElementById("textdownload").style.display = "none";

}

function convertCanvas(strType) {

if (strType == "JPEG") {

var oImg = Canvas2Image.saveAsJPEG(oCanvas, true);

}

if (!oImg) {

alert("Sorry, this browser is not capable of saving " + strType

+ " files!");

return false;

}

oImg.id = "canvasimage";

oImg.style.border = oCanvas.style.border;

oCanvas.parentNode.replaceChild(oImg, oCanvas);

showDownloadText();

}

saveCanvas(oCanvas, "JPEG");//在这里报错 说 无法找到 toDataURL 方法

function saveCanvas(pCanvas, strType) {

var bRes = false;

if (strType == "JPEG") {

bRes = Canvas2Image.saveAsJPEG(oCanvas);

}

if (!bRes) {

alert("Sorry, this browser is not capable of saving " + strType

+ " files!");

return false;

}

}

}

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页