添加图层剪切功能
This commit is contained in:
@@ -3200,6 +3200,49 @@ export class LayerManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 栅格化图层并返回Base64编码
|
||||
* @param {string} layerId 图层ID,默认使用当前活动图层
|
||||
* @returns {Promise<string|null>} Base64编码的图像字符串,失败时返回null
|
||||
*/
|
||||
async getLayerToBase64(layerId = null) {
|
||||
const targetLayerId = layerId || this.activeLayerId.value;
|
||||
if (!targetLayerId) {
|
||||
console.warn(this.t("没有指定要栅格化的图层"));
|
||||
return null;
|
||||
}
|
||||
|
||||
// 查找目标图层
|
||||
// const targetLayer = this.getLayerById(targetLayerId);
|
||||
const { layer: targetLayer } = findLayerRecursively(
|
||||
this.layers.value,
|
||||
targetLayerId
|
||||
);
|
||||
|
||||
if (!targetLayer) {
|
||||
console.error(this.t("图层不存在", { layerId: targetLayerId }));
|
||||
return null;
|
||||
}
|
||||
|
||||
// 直接创建和执行导出命令
|
||||
const command = new ExportLayerToImageCommand({
|
||||
canvas: this.canvas,
|
||||
layers: this.layers,
|
||||
layerId: targetLayerId,
|
||||
activeLayerId: this.activeLayerId,
|
||||
layerManager: this,
|
||||
});
|
||||
|
||||
command.undoable = false; // 导出操作通常不需要撤销
|
||||
|
||||
// 执行命令
|
||||
const result = await command.execute(false);
|
||||
if (result) {
|
||||
console.log(`✅ 成功导出图层: ${targetLayer.name}`);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 为组图层的活动选择组设置遮罩移动同步(修复版)
|
||||
* @param {fabric.ActiveSelection} activeSelection 活动选择组
|
||||
|
||||
Reference in New Issue
Block a user