深度画布

This commit is contained in:
lzp
2026-03-09 13:44:32 +08:00
parent 7048b3f646
commit bf5e5ca1a5
14 changed files with 3162 additions and 423 deletions

View File

@@ -0,0 +1,34 @@
import { fabric } from "fabric-with-all";
/**
* Factory for creating optimized fabric canvas instances
*/
export const createCanvas = (elementId, options = {}) => {
// Create the canvas instance
const canvas = new fabric.Canvas(elementId, {
enableRetinaScaling: true,
renderOnAddRemove: false,
preserveObjectStacking: true, // 保持对象堆叠顺序
// skipOffscreen: true, // 跳过离屏渲染
imageSmoothingEnabled: true, // 启用图像平滑 - 抗锯齿
imageSmoothingQuality: "high", // 设置高质量图像平滑
...options,
});
return canvas;
};
/**
* Utility to create a static canvas (for improved performance when interaction is not needed)
*/
export const createStaticCanvas = (elementId, options = {}) => {
const canvas = new fabric.StaticCanvas(elementId, {
enableRetinaScaling: true,
imageSmoothingEnabled: true, // 启用图像平滑 - 抗锯齿
imageSmoothingQuality: "high", // 设置高质量图像平滑
skipOffscreen: false, // 不跳过离屏渲染
...options,
});
return canvas;
};