Add Layer to PSD

Contents
[ ]

Overview

It’s a commonly used case. All you need is to open the file you need as a stream and then use Aspose.PSD to add this file as a new layer. You also can change the order of PSD Layers.

To add graphic file as Layer to PSD use the following code:

// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET
string outputFilePath = dataDir + "PsdResult.psd";
var filesList = new string[]
{
"PsdExample.psd",
"BmpExample.bmp",
"GifExample.gif",
"Jpeg2000Example.jpf",
"JpegExample.jpg",
"PngExample.png",
"TiffExample.tif",
};
using (var image = new PsdImage(200, 200))
{
foreach (var fileName in filesList)
{
string filePath = dataDir + fileName;
using (var stream = new FileStream(filePath, FileMode.Open))
{
Layer layer = null;
try
{
layer = new Layer(stream);
image.AddLayer(layer);
}
catch (Exception e)
{
if (layer != null)
{
layer.Dispose();
}
throw e;
}
}
}
image.Save(outputFilePath);
}

To change Layers order, please look at the following PSD Layers API Reference in Psd Image class