HOW to import an image AS smartobjectLayer

Hi, I try to import an image to PSD, it’s successful, but
is a normal Layer, how to be a smartobjectLayer.
Thank you all for your guidance.
code following:

using (var image = (PsdImage)Aspose.PSD.Image.Load(@"C:\001.psd"))
{

            string filePath = @"C:\test.jpg";
            using (var stream = new FileStream(filePath, FileMode.Open))
            {
                Layer layer = null;
                try
                {
                    layer = new Layer(stream);
                    image.AddLayer(layer); 
                }
                catch (Exception e2)
                {
                    if (layer != null)
                    {
                        layer.Dispose();
                    }
                    throw e2;
                }
            }

            image.Save(@"C:\003.psd");
        }

@Tim_Pan

I suggest you to please refer to following thread for your convenience.

Hi, Yes, I have read this article before.
I hope that the layer will be converted to a smart object layer and saved as a PSD. When using Adobe Photoshop open it is still a smart object layer.
I tried the new code and Run was successful and save PSD successful , but the output PSD cannot Open with Adobe Photoshop,Thank you.


        using (PsdImage image = (PsdImage)Image.Load(@"C:\test1.psd"))
        {


            image.SmartObjectProvider.ConvertToSmartObject(1);
            //Layers[1] convert to smart object layer

            image.Save(@"C:\test1ok.psd", new PsdOptions(image));

            image.Dispose();


        }

@Tim_Pan

Can you please share the source file, generated file and snapshot of PSD failing to get opened in Photoshop along with Photoshop version.

HI
My VS 2019 C# Project
[PSDtest.Zip]
When Adobe Photoshop open layerTest3.psd REEOR 506086.jpg (149.5 KB)

I expect the result of opening with Photoshop My expected result.jpg (296.1 KB)

Thank you

@Tim_Pan

I have created a ticket with ID PSDNET-790 in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

Is any good news?

@Tim_Pan

Can you please try using following sample code using Aspose.PSD for .NET 21.1.

            const string baseFolder = "PSDNET790_1\\";
            const string outputFolder = baseFolder + "output\\";

            // Tests that the layer, imported from an image, is converted to smart object layer and the saved PSD file is correct.
            using (PsdImage image = (PsdImage)Image.Load(baseFolder + @"layerTest1.psd"))
            {

                string layerFilePath = baseFolder + @"picture.jpg";
                string outputFilePath = outputFolder + "layerTest2.psd";
                string outputPngFilePath = Path.ChangeExtension(outputFilePath, ".png");
                using (var stream = new FileStream(layerFilePath, FileMode.Open))
                {
                    Layer layer = null;
                    try
                    {
                        layer = new Layer(stream);
                        image.AddLayer(layer);
                    }
                    catch (Exception)
                    {
                        if (layer != null)
                        {
                            layer.Dispose();
                        }

                        throw;
                    }

                    var layer2 = image.Layers[2];
                    var layer3 = image.SmartObjectProvider.ConvertToSmartObject(image.Layers.Length - 1);
                    var bounds = layer3.Bounds;
                    layer3.Left = (image.Width - layer3.Width) / 2;
                    layer3.Top = layer2.Top;
                    layer3.Right = layer3.Left + bounds.Width;
                    layer3.Bottom = layer3.Top + bounds.Height;

                    image.Save(outputFilePath);
                    image.Save(outputPngFilePath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
                }
            }

HI:
The situation is the same. The code works successfully, but the file cannot be opened in Photoshop. Which version of Photoshop are you using? ths.

@Tim_Pan

Actually, the reported issue has not been for PSD failing to open in Photoshop. Can you please share the Photoshop version along with snapshot of the issue so that we may verify that further on our end.

HI
1612766411419.jpg (23.3 KB)

1612617761161.jpg (72.2 KB)

[Google drive url]

layerTest2.zip (2.7 MB)

ths

@Tim_Pan

I am unable to access the dropbox link. Can you please share that again with us as I am getting the issue as mentioned in shared image.

image.png (41.2 KB)

hi

[Url removed]
ths

@Tim_Pan

Thank you for this. Can you please share the issue details.

The issues you have found earlier (filed as PSDNET-790) have been fixed in this update.

The test was successful and perfect. Thank you very much

@Tim_Pan

Thank you for sharing the feedback.