Fix:修复节点数量过多,画布尺寸过大无法导出png和pdf的问题

This commit is contained in:
街角小林
2023-12-26 12:20:12 +08:00
parent b7cb52b703
commit aed8e24afc

View File

@@ -106,6 +106,21 @@ class Export {
)
let imgWidth = img.width
let imgHeight = img.height
// 检查是否超出canvas支持的像素上限
const maxSize = 16384 / dpr
const maxArea = maxSize * maxSize
if (imgWidth * imgHeight > maxArea) {
let newWidth = null
let newHeight = null
if (imgWidth > maxSize) {
newWidth = maxArea / imgHeight
} else if (imgHeight > maxSize) {
newHeight = maxArea / imgWidth
}
const res = resizeImgSize(imgWidth, imgHeight, newWidth, newHeight)
imgWidth = res[0]
imgHeight = res[1]
}
canvas.width = imgWidth * dpr
canvas.height = imgHeight * dpr
canvas.style.width = imgWidth + 'px'
@@ -205,6 +220,7 @@ class Export {
const { str } = await this.getSvgData()
const svgUrl = await this.fixSvgStrAndToBlob(str)
const res = await this.svgToPng(svgUrl, transparent)
console.log(res)
return res
}