Hello! I have some problem with smart objects. I need to edit data in a inner smart and save. But when I do it without any update, unfortunately the smart loss effect. How to fix it? Many thanks. I have attached a source file. sampledog.zip (2.7 MB)
PsdLoadOptions psdLoadOptions = new PsdLoadOptions();
psdLoadOptions.LoadEffectsResource = true;
string inputFile = "c:\\psd\\sampledog.psd";
using (PsdImage psdImage = (PsdImage)Image.Load(inputFile, psdLoadOptions))
{
SmartObjectLayer smartObject = FindLayer("smart dog", psdImage) as SmartObjectLayer;
smartObject.Save("c:\\psd\\1.png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
PsdImage smartObjectPsdImage = (PsdImage)smartObject.LoadContents(psdLoadOptions);
// Doing something with psd...
// Convert to a smart object again and save psd/smart
SmartObjectLayer smartObject2 = smartObjectPsdImage.SmartObjectProvider.ConvertToSmartObject(smartObjectPsdImage.Layers);
smartObjectPsdImage.Save("c:\\psd\\2.png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
smartObject2.Save("c:\\psd\\3.png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
}
public Layer FindLayer(string layerName, PsdImage image)
{
// Get aa layers in PSD file
var layers = image.Layers;
// Find desired layer
foreach (var layer in layers)
{
// Match layer's name
if (string.Equals(layer.DisplayName, layerName, StringComparison.InvariantCultureIgnoreCase))
{
return layer;
}
}
return null;
}