ชั้น PSD
ภาพรวม
ชั้น Adobe® Photoshop® PSD เป็นหนึ่งในแนวคิดที่ดีที่สุดในการประมวลผลกราฟิก ชั้นมีข้อมูลเกี่ยวกับพิกเซล สามารถมีจำนวนช่องที่แตกต่างกัน
หนึ่งในส่วนสำคัญที่สุดของชั้นในเอกสาร Photoshop คือ ทรัพยากรชั้น คุณจะได้รับรายการที่ครอบคลุมทั้งหมดของ ทรัพยากรชั้น ที่รองรับใน PSD จากเอกสารของเรา
คุณสามารถค้นหา UI เพื่อจัดการชั้นบนภาพหน้าจอต่อไปนี้:
แต่ Aspose.PSD เชี่ยวชาญในการประมวลผลของชั้น PSD ผ่าน C# และ Java
เอกสารเพิ่มเติมสามารถพบในบทความนี้: การปรับแต่งรูปภาพ การปรับแต่งทั้งหมดสามารถประมวลผลไปยังตัวอย่าง PSD Preview และ Layer คุณสามารถพบข้อมูลเพิ่มเติมใน การอ้างอิง Aspose.PSD Raster Image API.
API ชั้น PSD ที่มี
- ผลกระทบชั้น
- คุณสมบัติชั้นทั่วไป
- มีตัวประมวลผลข้อมูลชั้น
ตัวอย่างการแก้ไขชั้นผ่านทาง C#
การเพิ่มชั้นใหม่
หากคุณต้องการเพิ่มชั้นเปล่าไปยัง ไฟล์ PSD ที่เปิด คุณสามารถใช้โค้ดต่อไปนี้
เพิ่มชั้นใหม่ไปยังไฟล์ PSD โดยใช้ API
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Make ability to add the newly generated regular layer to PsdImage | |
string sourceFileName = dataDir + "OneLayer.psd"; | |
string exportPath = dataDir + "OneLayerEdited.psd"; | |
string exportPathPng = dataDir + "OneLayerEdited.png"; | |
using (var im = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
// Preparing two int arrays | |
var data1 = new int[2500]; | |
var data2 = new int[2500]; | |
var rect1 = new Rectangle(0, 0, 50, 50); | |
var rect2 = new Rectangle(0, 0, 100, 25); | |
for (int i = 0; i < 2500; i++) | |
{ | |
data1[i] = -10000000; | |
data2[i] = -10000000; | |
} | |
var layer1 = im.AddRegularLayer(); | |
layer1.Left = 25; | |
layer1.Top = 25; | |
layer1.Right = 75; | |
layer1.Bottom = 75; | |
layer1.SaveArgb32Pixels(rect1, data1); | |
var layer2 = im.AddRegularLayer(); | |
layer2.Left = 25; | |
layer2.Top = 150; | |
layer2.Right = 125; | |
layer2.Bottom = 175; | |
layer2.SaveArgb32Pixels(rect2, data2); | |
// Save psd | |
im.Save(exportPath, new PsdOptions()); | |
// Save png | |
im.Save(exportPathPng, new PngOptions()); | |
} |
การเพิ่มชั้นใหม่จากไฟล์ Jpeg, Png, Gif, Ai, Tiff, Bmp
ไฟล์จากทุก รูปแบบที่สนับสนุน สามารถเพิ่มเป็นชั้นใหม่ในรูปของคุณ แต่คุณไม่สามารถโหลดมันโดยตรง
คุณสามารถใช้โค้ดด้านล่างเพื่อเพิ่มชั้น PSD ใหม่จากไฟล์ของรูปแบบที่สนับสนุนอะไรก็ได้จากสตรีม
// 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:
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Flatten whole PSD | |
string sourceFileName = dataDir + "ThreeRegularLayersSemiTransparent.psd"; | |
string exportPath = dataDir + "ThreeRegularLayersSemiTransparentFlattened.psd"; | |
using (var im = (PsdImage)(Image.Load(sourceFileName))) | |
{ | |
im.FlattenImage(); | |
im.Save(exportPath); | |
} | |
// Merge one layer in another | |
exportPath = dataDir + "ThreeRegularLayersSemiTransparentFlattenedLayerByLayer.psd"; | |
using (var im = (PsdImage)(Image.Load(sourceFileName))) | |
{ | |
var bottomLayer = im.Layers[0]; | |
var middleLayer = im.Layers[1]; | |
var topLayer = im.Layers[2]; | |
var layer1 = im.MergeLayers(bottomLayer, middleLayer); | |
var layer2 = im.MergeLayers(layer1, topLayer); | |
// Set up merged layers | |
im.Layers = new Layer[] { layer2 }; | |
im.Save(exportPath); | |
} |