เพิ่มเลเยอร์ใน PSD
Contents
[
Hide
]
ภาพรวม
นี่เป็นกรณีการใช้งานที่ใช้กันอย่างแพร่หลาย ทุกอย่างที่คุณต้องการคือเปิดไฟล์ที่คุณต้องการเป็นสตรีม แล้วใช้ Aspose.PSD เพื่อเพิ่มไฟล์นี้เป็นเลเยอร์ใหม่ คุณยังสามารถเปลี่ยนลำดับของ PSD Layers ได้ด้วย
หากต้องการเพิ่มไฟล์กราฟิกเป็นเลเยอร์ใน 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); | |
} |
หากต้องการเปลี่ยนลำดับของเลเยอร์ กรุณาดูที่ อ้างอิง API ของ PSD Layers ในคลาส Psd Image