使用图层
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(); | |
} |