پشتیبانی از LspfResource
Contents
[
Hide
]
پشتیبانی از LspfResource
LspfResource شامل تنظیمات مربوط به تنظیمات لایه محافظت شده است. Aspose.PSD پشتیبانی از LspfResource را در فایلهای PSD ارائه میدهد. برای این منظور، API کلاس LspfResource را ارائه میکند.
کد نمونه زیر نشان میدهد چگونه Aspose.PSD از LspfResource پشتیبانی میکند.
This file contains hidden or 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); | |
} | |
} |