fix: 修改红绿图模式下透明度恢复的默认值,优化导出逻辑
This commit is contained in:
@@ -827,7 +827,7 @@ export class CanvasManager {
|
||||
restoreOpacityInRedGreen:
|
||||
options.restoreOpacityInRedGreen !== undefined
|
||||
? options.restoreOpacityInRedGreen
|
||||
: true, // 默认在红绿图模式下恢复透明度
|
||||
: false, // 默认在红绿图模式下恢复透明度
|
||||
};
|
||||
|
||||
// 如果在红绿图模式下且没有指定具体的图层,自动包含所有普通图层
|
||||
@@ -851,7 +851,6 @@ export class CanvasManager {
|
||||
console.log("红绿图模式导出图层:", normalLayerIds);
|
||||
}
|
||||
}
|
||||
|
||||
return await this.exportManager.exportImage(enhancedOptions);
|
||||
} catch (error) {
|
||||
console.error("CanvasManager导出图片失败:", error);
|
||||
|
||||
@@ -53,10 +53,10 @@ export class ExportManager {
|
||||
return this._exportMultipleLayers(
|
||||
layerIdArray,
|
||||
expPicType,
|
||||
isContainBg,
|
||||
isContainFixed,
|
||||
isRedGreenMode,
|
||||
restoreOpacityInRedGreen,
|
||||
isContainBg,
|
||||
isCropByBg
|
||||
);
|
||||
}
|
||||
@@ -619,7 +619,7 @@ export class ExportManager {
|
||||
// this.canvasManager?.canvasHeight?.value || this.canvas.height;
|
||||
|
||||
// console.log(`普通模式导出,画布尺寸: ${canvasWidth}x${canvasHeight}`);
|
||||
|
||||
debugger;
|
||||
// 使用图层栅格化的方法导出图片
|
||||
const dataURL = await createRasterizedImage({
|
||||
canvas: this.canvas,
|
||||
@@ -629,6 +629,7 @@ export class ExportManager {
|
||||
maskObject: maskObject ?? null, // 使用裁剪对象
|
||||
trimWhitespace: true, // 裁剪空白
|
||||
trimPadding: 0, // 裁剪边距
|
||||
restoreOpacityInRedGreen,
|
||||
});
|
||||
|
||||
console.log("导出图片数据URL:", dataURL);
|
||||
|
||||
@@ -55,10 +55,14 @@ export class RedGreenModeManager {
|
||||
if (typeof options.normalLayerOpacity === "number") {
|
||||
if (options.normalLayerOpacity > 1) {
|
||||
// 如果大于1,认为是百分比值(0-100)
|
||||
this.normalLayerOpacity = Math.max(0, Math.min(100, options.normalLayerOpacity)) / 100;
|
||||
this.normalLayerOpacity =
|
||||
Math.max(0, Math.min(100, options.normalLayerOpacity)) / 100;
|
||||
} else {
|
||||
// 如果小于等于1,认为是小数值(0-1)
|
||||
this.normalLayerOpacity = Math.max(0, Math.min(1, options.normalLayerOpacity));
|
||||
this.normalLayerOpacity = Math.max(
|
||||
0,
|
||||
Math.min(1, options.normalLayerOpacity)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +97,10 @@ export class RedGreenModeManager {
|
||||
this.registerRedGreenMouseUpEvent();
|
||||
|
||||
// 启用图层管理器的红绿图模式
|
||||
if (this.layerManager && typeof this.layerManager.enableRedGreenMode === "function") {
|
||||
if (
|
||||
this.layerManager &&
|
||||
typeof this.layerManager.enableRedGreenMode === "function"
|
||||
) {
|
||||
this.layerManager.enableRedGreenMode();
|
||||
}
|
||||
|
||||
@@ -132,7 +139,9 @@ export class RedGreenModeManager {
|
||||
return;
|
||||
}
|
||||
if (this.onImageGenerated) {
|
||||
const imageData = await this.canvasManager.exportImage();
|
||||
const imageData = await this.canvasManager.exportImage({
|
||||
restoreOpacityInRedGreen: true, // 恢复红绿图模式下的透明度
|
||||
});
|
||||
this.onImageGenerated(imageData);
|
||||
}
|
||||
});
|
||||
@@ -187,7 +196,9 @@ export class RedGreenModeManager {
|
||||
// 更新内部状态
|
||||
this.normalLayerOpacity = normalizedOpacity;
|
||||
|
||||
console.log(`普通图层透明度已更新为: ${Math.round(normalizedOpacity * 100)}%`);
|
||||
console.log(
|
||||
`普通图层透明度已更新为: ${Math.round(normalizedOpacity * 100)}%`
|
||||
);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error("更新普通图层透明度失败:", error);
|
||||
@@ -271,7 +282,9 @@ export class RedGreenModeManager {
|
||||
const layers = this.layerManager.layers.value || [];
|
||||
const backgroundLayer = layers.find((layer) => layer.isBackground);
|
||||
const fixedLayer = layers.find((layer) => layer.isFixed);
|
||||
const normalLayers = layers.filter((layer) => !layer.isBackground && !layer.isFixed);
|
||||
const normalLayers = layers.filter(
|
||||
(layer) => !layer.isBackground && !layer.isFixed
|
||||
);
|
||||
|
||||
return {
|
||||
backgroundLayer:
|
||||
@@ -307,7 +320,10 @@ export class RedGreenModeManager {
|
||||
cleanup() {
|
||||
try {
|
||||
// 禁用图层管理器的红绿图模式
|
||||
if (this.layerManager && typeof this.layerManager.disableRedGreenMode === "function") {
|
||||
if (
|
||||
this.layerManager &&
|
||||
typeof this.layerManager.disableRedGreenMode === "function"
|
||||
) {
|
||||
this.layerManager.disableRedGreenMode();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user