深度画布功能

This commit is contained in:
lzp
2026-03-11 15:34:56 +08:00
parent 5e063f919d
commit c87ed70e7c
46 changed files with 12646 additions and 224 deletions

View File

@@ -0,0 +1,26 @@
import { createStaticCanvas } from './canvasFactory'
import { getObjectsBoundingBox, cloneObjects } from './canvasMethod'
/** 导出指定对象 */
export async function exportObjectsToImage(objects = [], isDetails = false) {
const clonedObjects = await cloneObjects(objects)
const boundingBox = await getObjectsBoundingBox(clonedObjects)
const staticCanvas = createStaticCanvas(document.createElement('canvas'))
staticCanvas.setWidth(boundingBox.width)
staticCanvas.setHeight(boundingBox.height)
clonedObjects.forEach(obj => {
obj.set({
left: obj.left - boundingBox.left,
top: obj.top - boundingBox.top,
})
staticCanvas.add(obj)
})
// 导出图片
const dataURL = staticCanvas.toDataURL({
type: 'image/png',
quality: 1,
})
return isDetails ? {
url: dataURL,
...boundingBox,
} : dataURL
}