将图层添加到PSD
Contents
[
Hide
]
概述
这是一个常用情况。您只需要打开需要的文件作为流,然后使用Aspose.PSD将此文件作为新图层添加进去。您还可以更改PSD图层的顺序。
要将图形文件作为图层添加到PSD,请使用以下代码:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} |
要更改图层顺序,请参阅以下 PSD图层API参考 在 Psd Image 类中