怎么替换图层图片实现自动更新?
var dataDir = AppDomain.CurrentDomain.BaseDirectory;
var psdFile = Path.Combine(dataDir, "test.psd");
var replaceImg = Path.Combine(dataDir, "test.png");
const string layerName = "插画-1-透明";
Console.WriteLine(dataDir);
Console.WriteLine(psdFile);
Console.WriteLine(replaceImg);
using var image = (PsdImage)Image.Load(psdFile);
var layerToReplaces1 = GetLayersByDisplayName<LayerGroup>(image, "Layer group: 替换");
foreach (var layerGroup in layerToReplaces1)
{
Console.WriteLine($"SmartObjectLayer: {layerGroup.DisplayName}");
foreach (var layer in layerGroup.Layers)
{
Console.WriteLine(layer.DisplayName);
if (layer.DisplayName != layerName) continue;
var smartObjectLayer = (SmartObjectLayer)layer;
smartObjectLayer.ReplaceContents(replaceImg);
smartObjectLayer.UpdateModifiedContent();
}
}
image.SmartObjectProvider.UpdateAllModifiedContent();
image.Save(Path.Combine(dataDir, "test1.psd"), new PsdOptions(image));
var jpegOptions = new JpegOptions();
jpegOptions.Quality = 12;
jpegOptions.ColorType = JpegCompressionColorMode.Rgb;
image.Save(Path.Combine(dataDir, "test1.jpg"), jpegOptions);
问题:
我用代码无法实现和 Photo shop 一样的替换图层内容的效果,我该如何修改我的代码?
PSD File : PSD
下面是我要实现的效果
替换前 iShot_2024-11-06_12.55.00.jpg (674.9 KB)
替换后 iShot_2024-11-06_12.55.38.jpg (672.6 KB)