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); | |
} | |
} |