LspfResource 지원
Contents
[
Hide
]
LspfResource 지원
LspfResource에는 레이어 보호 설정에 관한 설정이 포함되어 있습니다. Aspose.PSD는 PSD 파일에서 LspfResource를 지원합니다. API는 LspfResource 클래스를 제공합니다.
다음 코드 스니펫은 Aspose.PSD가 LspfResource를 지원하는 방법을 보여줍니다.
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-Java | |
public static void main(String[] args) { | |
String sourceDir = Utils.GetDataDir_PSD(); | |
String outputDir = Utils.GetDataDir_Output(); | |
final String actualPropertyValueIsWrongMessage = "Expected property value is not equal to actual value"; | |
String sourceFileName = sourceDir + "SampleForLspfResource.psd"; | |
String destinationFileName = outputDir + "SampleForLspfResource_out.psd"; | |
boolean isRequiredResourceFound = false; | |
PsdImage im = null; | |
try { | |
im = (PsdImage) Image.load(sourceFileName); | |
for (Layer layer : im.getLayers()) { | |
for (LayerResource layerResource : layer.getResources()) { | |
if (layerResource instanceof LspfResource) { | |
LspfResource resource = (LspfResource) layerResource; | |
isRequiredResourceFound = true; | |
assertIsTrue(!resource.isCompositeProtected(), actualPropertyValueIsWrongMessage); | |
assertIsTrue(!resource.isPositionProtected(), actualPropertyValueIsWrongMessage); | |
assertIsTrue(!resource.isTransparencyProtected(), actualPropertyValueIsWrongMessage); | |
// Test editing and saving | |
resource.setCompositeProtected(true); | |
assertIsTrue(resource.isCompositeProtected(), actualPropertyValueIsWrongMessage); | |
assertIsTrue(!resource.isPositionProtected(), actualPropertyValueIsWrongMessage); | |
assertIsTrue(!resource.isTransparencyProtected(), actualPropertyValueIsWrongMessage); | |
resource.setCompositeProtected(false); | |
resource.setPositionProtected(true); | |
assertIsTrue(!resource.isCompositeProtected(), actualPropertyValueIsWrongMessage); | |
assertIsTrue(resource.isPositionProtected(), actualPropertyValueIsWrongMessage); | |
assertIsTrue(!resource.isTransparencyProtected(), actualPropertyValueIsWrongMessage); | |
resource.setPositionProtected(false); | |
resource.setTransparencyProtected(true); | |
assertIsTrue(!resource.isCompositeProtected(), actualPropertyValueIsWrongMessage); | |
assertIsTrue(!resource.isPositionProtected(), actualPropertyValueIsWrongMessage); | |
assertIsTrue(resource.isTransparencyProtected(), actualPropertyValueIsWrongMessage); | |
resource.setCompositeProtected(true); | |
resource.setPositionProtected(true); | |
resource.setTransparencyProtected(true); | |
im.save(destinationFileName); | |
break; | |
} | |
} | |
} | |
} finally { | |
if (im != null) im.dispose(); | |
} | |
assertIsTrue(isRequiredResourceFound, "The specified LspfResource not found"); | |
isRequiredResourceFound = false; | |
PsdImage im2 = null; | |
try { | |
im2 = (PsdImage) Image.load(destinationFileName); | |
for (Layer layer : im2.getLayers()) { | |
for (LayerResource layerResource : layer.getResources()) { | |
if (layerResource instanceof LspfResource) { | |
LspfResource resource = (LspfResource) layerResource; | |
isRequiredResourceFound = true; | |
assertIsTrue(resource.isCompositeProtected(), actualPropertyValueIsWrongMessage); | |
assertIsTrue(resource.isPositionProtected(), actualPropertyValueIsWrongMessage); | |
assertIsTrue(resource.isTransparencyProtected(), actualPropertyValueIsWrongMessage); | |
break; | |
} | |
} | |
} | |
} finally { | |
if (im2 != null) im2.dispose(); | |
} | |
assertIsTrue(isRequiredResourceFound, "The specified LspfResource not found"); | |
System.out.println("LspfResource updating works as expected. Press any key."); | |
} | |
private static void assertIsTrue(boolean condition, String message) { | |
if (!condition) { | |
throw new FormatException(message); | |
} | |
} |