feat: 添加导出图层功能,支持将图层转换为位图图像并下载
This commit is contained in:
@@ -45,7 +45,10 @@ import {
|
||||
BackgroundSizeWithScaleCommand,
|
||||
} from "../commands/BackgroundCommands";
|
||||
import { MergeGroupLayerCommand } from "../commands/GroupCommands";
|
||||
import { RasterizeLayerCommand } from "../commands/RasterizeLayerCommand";
|
||||
import {
|
||||
ExportLayerToImageCommand,
|
||||
RasterizeLayerCommand,
|
||||
} from "../commands/RasterizeLayerCommand";
|
||||
|
||||
// 导入图层排序相关类和混入
|
||||
import {
|
||||
@@ -2865,6 +2868,57 @@ export class LayerManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出图层 -- 下载图层图片
|
||||
* @param {string} layerId 图层ID,默认使用当前活动图层
|
||||
*/
|
||||
async exportLayerToImage(layerId = null) {
|
||||
const targetLayerId = layerId || this.activeLayerId.value;
|
||||
|
||||
if (!targetLayerId) {
|
||||
console.warn($t("没有指定要栅格化的图层"));
|
||||
return false;
|
||||
}
|
||||
|
||||
// 查找目标图层
|
||||
// const targetLayer = this.getLayerById(targetLayerId);
|
||||
const { layer: targetLayer } = findLayerRecursively(
|
||||
this.layers.value,
|
||||
targetLayerId
|
||||
);
|
||||
|
||||
if (!targetLayer) {
|
||||
console.error($t("图层不存在", { layerId: targetLayerId }));
|
||||
return false;
|
||||
}
|
||||
|
||||
// 直接创建和执行导出命令
|
||||
const command = new ExportLayerToImageCommand({
|
||||
canvas: this.canvas,
|
||||
layers: this.layers,
|
||||
layerId: targetLayerId,
|
||||
activeLayerId: this.activeLayerId,
|
||||
layerManager: this,
|
||||
});
|
||||
|
||||
command.undoable = false; // 导出操作通常不需要撤销
|
||||
|
||||
// 执行命令
|
||||
if (this.commandManager) {
|
||||
const result = await this.commandManager.execute(command);
|
||||
if (result) {
|
||||
console.log(`✅ 成功导出图层: ${targetLayer.name}`);
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
const result = await command.execute();
|
||||
if (result) {
|
||||
console.log(`✅ 成功导出图层: ${targetLayer.name}`);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新图层缩略图
|
||||
* @param {string} layerId 图层ID
|
||||
|
||||
@@ -22,6 +22,7 @@ export class RedGreenModeManager {
|
||||
// 图片URL
|
||||
this.clothingImageUrl = null;
|
||||
this.redGreenImageUrl = null;
|
||||
this.clothingImageOpts = options.clothingImageOpts || null;
|
||||
|
||||
// 回调函数
|
||||
this.onImageGenerated = null;
|
||||
@@ -77,6 +78,7 @@ export class RedGreenModeManager {
|
||||
toolManager: this.toolManager,
|
||||
clothingImageUrl: this.clothingImageUrl,
|
||||
redGreenImageUrl: this.redGreenImageUrl,
|
||||
clothingImageOpts: this.clothingImageOpts,
|
||||
normalLayerOpacity: this.normalLayerOpacity,
|
||||
onImageGenerated: this.onImageGenerated,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user