Files
aida_front/src/component/Canvas/CanvasEditor/utils/canvasFactory.js

36 lines
1.2 KiB
JavaScript
Raw Normal View History

2025-06-18 11:05:23 +08:00
import { fabric } from "fabric-with-all";
2025-06-09 10:25:54 +08:00
import { canvasConfig } from "../config/canvasConfig";
/**
* Factory for creating optimized fabric canvas instances
*/
export const createCanvas = (elementId, options = {}) => {
// Create the canvas instance
const canvas = new fabric.Canvas(elementId, {
enableRetinaScaling: canvasConfig.enableRetinaScaling,
renderOnAddRemove: false,
preserveObjectStacking: true, // 保持对象堆叠顺序
// skipOffscreen: true, // 跳过离屏渲染
imageSmoothingEnabled: true, // 启用图像平滑 - 抗锯齿
imageSmoothingQuality: "high", // 设置高质量图像平滑
2025-06-09 10:25:54 +08:00
...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: canvasConfig.enableRetinaScaling,
imageSmoothingEnabled: true, // 启用图像平滑 - 抗锯齿
imageSmoothingQuality: "high", // 设置高质量图像平滑
skipOffscreen: false, // 不跳过离屏渲染
2025-06-09 10:25:54 +08:00
...options,
});
return canvas;
};