Free Support Forum - aspose.com

SmartObject ReplaceContents have problem with reRender

Hello,
I have a problem when using the ReplaceContents function, after I ReplaceContents, PSD result file it did not work as I expected.

  1. Using Photoshop CC 2018
    This is my PSD file (Render.psd GoogleDrive)
    image.jpg (347.3 KB)
    I’m using photoshop cc 2018 and right click on SmartObject sleeves hoodie upload and choose Replace 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
  2. 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)

Thank you for reading and support.

@huunhat07

I have verified the images shared by you and we need to investigate this further on our end. A ticket with ID PSDNET-769 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked wit the issue so that you may be notified once the issue will be fixed.

1 Like