Hello,
I have a problem when using the ReplaceContents function, after I ReplaceContents, PSD result file it did not work as I expected.
- Using Photoshop CC 2018
This is my PSD file ([Render.psd GoogleDrive](https://drive.google.com/file/d/1crKWaqe2x5iRrb4iCG6_lTQ2zx7lR8a7/view?usp=sharing)
)
image.jpg (347.3 KB)
I’m using photoshop cc 2018 and right click on SmartObjectsleeves hoodie upload
and chooseReplace Contents
then select new sleeves image file (sleeves hoodie.jpg (511.7 KB))
.
This is result:
image.jpg (331.7 KB)
This is the right result I expected - Using ASPOSE.PSD dot Net
This is my code:
namespace PSD
{
class Program
{
static void Main(string[] args)
{
using (PsdImage image = (PsdImage)Image.Load(“render.psd”))
{
foreach (var layer in image.Layers)
{
Console.WriteLine("Layer: {0}", layer.DisplayName);
}
var smartObjectLayer = (SmartObjectLayer)FindLayer("sleeves hoodie upload", image);
using (var img = new PsdImage(5000, 3600))
{
using (Stream stream = new FileStream(@"sleeves hoodie.jpg", FileMode.Open))
{
Layer layer = null;
try
{
layer = new Layer(stream);
img.AddLayer(layer);
}
catch (Exception e)
{
if (layer != null)
{
layer.Dispose();
}
throw e;
}
smartObjectLayer.ReplaceContents(img);
Console.WriteLine("Replace contents");
}
}
image.SmartObjectProvider.UpdateAllModifiedContent();
image.Save("ouput_hoodie.psd", new PsdOptions(image));
Console.WriteLine("Press enter to close...");
Console.ReadLine();
}
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;
}
}
}
}
And this is result when I run code
image.jpg (345.1 KB)
[ouput_hoodie.psd (Google drive link)]
Files to test:
sleeves hoodie.jpg (511.7 KB)
[Render.psd (Google Drive Link)](https://drive.google.com/file/d/1crKWaqe2x5iRrb4iCG6_lTQ2zx7lR8a7/view?usp=sharing)
Thank you for reading and support.