This commit is contained in:
wxd
2024-10-03 16:17:15 +08:00
parent 44912baee3
commit 12b9dbdfbf

View File

@@ -298,41 +298,19 @@ export default defineComponent({
} }
let submit = ()=>{ let submit = ()=>{
const newCanvas = document.createElement('canvas'); const newCanvas = document.createElement('canvas');
let exportCanvas = new fabric.Canvas(newCanvas, { newCanvas.width = canvasImgData.width;
width: canvasImgData.width, newCanvas.height = canvasImgData.height;
height:canvasImgData.height, const newCtx = newCanvas.getContext('2d');
isDrawingMode: false, // 开启绘图模式 newCtx.drawImage(
}); canvas,
fabric.Image.fromURL(canvas.toDataURL('png'), function(img) { 0, 0,
img.scaleToWidth(exportCanvas.width); canvas.width,
img.scaleToHeight(exportCanvas.height); canvas.height,
img.set({ 0, 0,
scaleX: exportCanvas.width / img.width, newCanvas.width,
scaleY: exportCanvas.height / img.height newCanvas.height
}); );
exportCanvas.setBackgroundImage(img, exportCanvas.renderAll.bind(exportCanvas)); emit('submitLiquefaction',newCanvas.toDataURL('image/png'))
let data = exportCanvas.toDataURL({
format: "png", // 导出格式为 PNG
quality: 1, // 图片质量为 1最高质量
});
},{ crossOrigin: "Anonymous" });
// newCanvas.width = canvasImgData.width;
// newCanvas.height = canvasImgData.height;
// const newCtx = newCanvas.getContext('2d');
// newCtx.drawImage(
// canvas,
// 0, 0,
// canvas.width,
// canvas.height,
// 0, 0,
// newCanvas.width,
// newCanvas.height
// );
// console.log(exportCanvas.toDataURL('jpg'));
emit('submitLiquefaction',canvas.toDataURL('image/png'))
cancelDsign() cancelDsign()
} }
return { return {