Skip to content

Commit

Permalink
修改默认canvas生成宽高问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Loren-Wang committed Jul 5, 2024
1 parent eacc0b3 commit 46addca
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions src/common/whiteboard-wrapper/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,7 @@ export const mergeCanvasImage = async (scenes: (() => Promise<HTMLCanvasElement
for (const canvasPromise of scenes) {
let canvas = await canvasPromise();
if("data:," === canvas?.toDataURL()){
canvas = getDefaultCanvas(width,height)
}
if (canvas) {
width = Math.max(canvas.width, width);
height = Math.max(canvas.height, height);
}
}
for (const canvasPromise of scenes) {
let canvas = await canvasPromise();
if("data:," === canvas?.toDataURL()){
canvas = getDefaultCanvas(width,height)
canvas = getDefaultCanvas()
}
if (canvas) {
width = Math.max(canvas.width, width);
Expand All @@ -168,13 +158,13 @@ export const mergeCanvasImage = async (scenes: (() => Promise<HTMLCanvasElement
return bigCanvas;
};

function getDefaultCanvas(width:number,height:number):HTMLCanvasElement{
function getDefaultCanvas():HTMLCanvasElement{
// 创建新的 canvas 元素
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d')!;
// 设置 canvas 尺寸为图像尺寸
canvas.width = width;
canvas.height = height;
canvas.width = 100;
canvas.height = 100;
const ctx = canvas.getContext('2d')!;
// 设置填充颜色为白色,并填充整个 canvas
ctx.fillStyle = 'white';
ctx.fillRect(0, 0, canvas.width, canvas.height);
Expand Down

0 comments on commit 46addca

Please sign in to comment.