การทำงานกับชั้น
Contents
[
Hide
]
การสนับสนุนของชั้นที่เชื่อมโยง
การเชื่อมโยงชั้นเหมือนกับการจัดกลุ่มชั้น หากคุณกำลังเชื่อมโยงชั้นสองชั้นขึ้นไป มันจะทำให้คุณสามารถทำการเปลี่ยนแปลงบางอย่างกับทั้งสองชั้นที่เชื่อมโยงกันได้ ตัวอย่างเช่น หากคุณใช้การแปลงแล้วให้กับหนึ่งชั้น จะถูกนำไปใช้กับชั้นเชื่อมไปกับอื่นทั้งหมด บทความนี้สาธิตถึงวิธีการรับและยกเลิกการเชื่อมโยงชั้นโดยใช้ Aspose.PSD for Java.
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
String dataDir = Utils.getDataDir(SupportOfLinkedLayer.class) + "ModifyingAndConvertingImages/"; | |
PsdImage psd = (PsdImage) Image.load(dataDir + "LinkedLayerexample.psd"); | |
try { | |
Layer[] layers = psd.getLayers(); | |
short layersLinkGroupId = psd.getLinkedLayersManager().linkLayers(layers); | |
short linkGroupId = psd.getLinkedLayersManager().getLinkGroupId(layers[0]); | |
if (layersLinkGroupId != linkGroupId) { | |
throw new Exception("layersLinkGroupId and linkGroupId are not equal."); | |
} | |
Layer[] linkedLayers = psd.getLinkedLayersManager().getLayersByLinkGroupId(linkGroupId); | |
for (Layer linkedLayer : linkedLayers) { | |
psd.getLinkedLayersManager().unlinkLayer(linkedLayer); | |
} | |
linkedLayers = psd.getLinkedLayersManager().getLayersByLinkGroupId(linkGroupId); | |
if (linkedLayers != null) { | |
throw new Exception("The linkedLayers field is not NULL."); | |
} | |
psd.save(dataDir + "LinkedLayerexample_output.psd"); | |
} finally { | |
psd.dispose(); | |
} |