This commit is contained in:
yumoqing 2024-08-01 13:46:05 +08:00
parent 03179fa970
commit 1f39d86557

View File

@ -28,6 +28,9 @@ bricks.Image = class extends bricks.JsWidget {
this.dom_element.style.height = this.height;
}
}
removeBase64Header(base64String) {
return base64String.replace(/^data:[^;]*;base64,/, '');
}
base64(){
const image = this.dom_element;
// 创建一个画布来绘制图像
@ -42,7 +45,8 @@ bricks.Image = class extends bricks.JsWidget {
ctx.drawImage(image, 0, 0);
// 获取画布数据并转换为 base64
const dataURL = canvas.toDataURL('image/png'); // 可以根据需要修改图像格式
var dataURL = canvas.toDataURL('image/png'); // 可以根据需要修改图像格式
dataURL = this.removeBase64Header(dataURL);
console.log(dataURL);
return dataURL;
}