We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Remove base layer


I am trying to create psd file with .Net, its working fine, but i can see one layer on bottom named Background in all files alongwith the layers which i added. I want to overwrite the base layer with my first image, how to do that?

image.png (26.1 KB)
In the above image, top three layer images I have added and saved.

The actual i need is like below
image.png (4.9 KB)

Here is the code for saving psd file
Aspose.PSD.License license = new Aspose.PSD.License();

// Initialize PsdImage class object
PsdImage image = new PsdImage(width, height);
Layer layer = null;
for (int i = 0; i < count * 2; i = i + 2)
string fname = args[i + 3];
string lname = args[i + 4];

    Stream stream = new FileStream(fname, FileMode.Open);

    layer = new Layer(stream);
    layer.DisplayName = lname;
     // Add input image as layer to PSD image

string outputpath = args[len - 1];
Please suggest.

Also, is there any size limit for the files to add in layer ? because, sometimes if i save with bigger size image, then psd file is saving with 0 kb.



Currently, the API does not have a method to remove layers from PsdImage.
To remove layers from PsdImage, the customer can use the following code sample:

        string sourceFile = "psdImage.psd";
        using (var image = (PsdImage)Image.Load(sourceFile))
            var layersList = new List<Layer>(image.Layers); // gets all PsdImage layers as layer List

            layersList.RemoveAt(0); // remove layer from list

            image.Layers = layersList.ToArray(); // sets updated layer list back to PsdImage

Secondly, for the scenario shared by you, please share the working sample code along with source file and generated output with us.


Thanks for the reply and a solution.

This method works fine for me. Will go with this.



It’s good to know that suggested solution proves to be working.