大雪无痕
大雪无痕
  • 发布:2015-05-28 18:17
  • 更新:2017-12-04 10:07
  • 阅读:6580

canvas.toDataURL()返回空值是怎么回事?

分类:HTML5+

ar img = new Image();
img.src = path; // 传过来的图片路径在这里用。
//alert(img.src);
img.onload = function () {
if(img.complete==true){
var that = this;
//生成比例
var w = that.width,
h = that.height
scale = w / h;
w = 480 || w; //480 你想压缩到多大,改这里
h = w / scale;
alert("w=" + w +",h=" + h);
//生成canvas
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
$(canvas).attr({width : w, height : h});
//ctx.drawImage(that, 0, 0, w, h);
var base64 = canvas.toDataURL("image/png");
var pic = document.getElementById("x");
pic.src = base64; //这里丢到img 的 src 里面就能看到效果了
//pic.src = path;
}
}

程序从手机相册选择照片,var base64 = canvas.toDataURL("image/png");得到的值是data:,
谁知道这是什么原因造成的???
同样的程序在FF中可以取到值,在Hbuilder中联机调试,手机上得不到返回值。

移动APP项目,Android系统

2015-05-28 18:17 负责人:无 分享
已邀请:
ghj19930

ghj19930

这个最后解决了吗

该问题目前已经被锁定, 无法添加新回复