1金币
本帖最后由 ngqj 于 2022-9-23 17:00 编辑
请教一下大佬,图片转base64的js以前一直都正常用的,现在突然不行了
应用是https的,原js代码:var img = `https://${window.location.host}/Upload/`+Forguncy.Page.getCell("jpg").getValue();
function getBase64Image(img) {
var canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, img.width, img.height);
var ext = img.src.substring(img.src.lastIndexOf(".")+1).toLowerCase();
var dataURL = canvas.toDataURL("image/"+ext);
return dataURL;
}
var image = new Image();
image.src = img;
image.onload = function(){
var base64 = getBase64Image(image);
console.log(base64);
Forguncy.Page.getCell('touxiang').setValue(base64);
}
如果是HTTP应用,代码改成下面这样还是可以跑的,请问怎么在https的应用上运行代码呢,望大佬赐教
var img = `http://${window.location.host}/Upload/`+Forguncy.Page.getCell("jpg").getValue();
function getBase64Image(img) {
var canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, img.width, img.height);
var ext = img.src.substring(img.src.lastIndexOf(".")+1).toLowerCase();
var dataURL = canvas.toDataURL("image/"+ext);
return dataURL;
}
var image = new Image();
image.src = img;
image.onload = function(){
var base64 = getBase64Image(image);
console.log(base64);
Forguncy.Page.getCell('touxiang').setValue(base64);
}
|
|