mirror of
https://github.com/Azornes/Comfyui-LayerForge.git
synced 2026-03-21 20:52:12 -03:00
Fix matting: refresh image after background removal
Fixed an issue where images were not immediately refreshed after background removal (matting). Now, the canvas updates instantly when the background is removed, ensuring correct display without requiring manual scaling or other actions.
This commit is contained in:
@@ -961,17 +961,13 @@ export class CanvasLayers {
|
||||
}
|
||||
async getLayerImageData(layer) {
|
||||
try {
|
||||
const { canvas: tempCanvas, ctx: tempCtx } = createCanvas(layer.width, layer.height, '2d', { willReadFrequently: true });
|
||||
const width = layer.originalWidth || layer.width;
|
||||
const height = layer.originalHeight || layer.height;
|
||||
const { canvas: tempCanvas, ctx: tempCtx } = createCanvas(width, height, '2d', { willReadFrequently: true });
|
||||
if (!tempCtx)
|
||||
throw new Error("Could not create canvas context");
|
||||
// We need to draw the layer relative to the new canvas, so we "move" it to 0,0
|
||||
// by creating a temporary layer object for drawing.
|
||||
const layerToDraw = {
|
||||
...layer,
|
||||
x: 0,
|
||||
y: 0,
|
||||
};
|
||||
this._drawLayer(tempCtx, layerToDraw);
|
||||
// Use original image directly to ensure full quality
|
||||
tempCtx.drawImage(layer.image, 0, 0, width, height);
|
||||
const dataUrl = tempCanvas.toDataURL('image/png');
|
||||
if (!dataUrl.startsWith('data:image/png;base64,')) {
|
||||
throw new Error("Invalid image data format");
|
||||
|
||||
@@ -430,6 +430,8 @@ async function createCanvasWidget(node, widget, app) {
|
||||
delete newLayer.imageId;
|
||||
canvas.layers[selectedLayerIndex] = newLayer;
|
||||
canvas.canvasSelection.updateSelection([newLayer]);
|
||||
// Invalidate processed image cache when layer image changes (matting)
|
||||
canvas.canvasLayers.invalidateProcessedImageCache(newLayer.id);
|
||||
canvas.render();
|
||||
canvas.saveState();
|
||||
showSuccessNotification("Background removed successfully!");
|
||||
|
||||
Reference in New Issue
Block a user