深度画布功能
This commit is contained in:
26
src/components/Canvas/DepthCanvas/tools/exportMethod.js
Normal file
26
src/components/Canvas/DepthCanvas/tools/exportMethod.js
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user