uni app ios render.js canvas 设置了img.crossOrigin = "anonymous"; 怎么不往下执行
let self = this;
img.src = data;
// img.crossOrigin = "Anonymous"
img.crossOrigin = "anonymous";
img.onload = function(e) {
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
//在css中不要直接给img设置宽高,否则此处会获取到css设置的值
var width = img.width;
var height = img.height;
//比较图片宽高设置图片显示和canvas画布尺寸
if (width > height) {
if (width >= 1080) {
height = Math.round(height *= 1080 / width);
width = 1080;
}
} else {
if (height >= 1440) {
width = Math.round(width *= 1440 / height);
height = 1440;
}
}
canvas.width = width; //设置新的图片的宽度
canvas.height = height; //设置新的图片的长度
ctx.drawImage(img, 0, 0, width, height); //绘图
try {
// var dataURL = canvas.toDataURL("image/jpeg", 0.8);
canvas.toBlob((blob) => {
// 调用回调函数,传入压缩后的图片数据
console.log(blob, '----blob')
}, 'image/jpeg', 0.8);
// console.log(dataURL,'--dataURL')
} catch (error) {
console.log(error, '-----error')
}
// var dataURL = canvas.toDataURL("image/jpeg", 0.8); //供img标签使用的src路径
// self.$ownerInstance.callMethod('NewuploadFile', {
// fileUrl: dataURL,
// url: data,
// })
}
},```
0 个回复