在文本层中渲染不同颜色的文本
Contents
[
Hide
]
在文本层中渲染不同颜色的文本
Aspose.PSD支持将PSD文件转换为图像。在PSD文件中的文本包含不同颜色时,可能会出现这种情况。Aspose.PSD支持将这种PSD文件转换为图像。
以下代码片段演示了将带有文本层中不同颜色的PSD文件转换为PNG:
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 | |
String sourceDir = Utils.GetDataDir_PSD(); | |
String outputDir = Utils.GetDataDir_Output(); | |
String targetFilePath = sourceDir + "text_ethalon_different_colors.psd"; | |
String resultFilePath = outputDir + "RenderTextWithDifferentColorsInTextLayer_out.png"; | |
PsdImage psdImage = null; | |
try { | |
psdImage = (PsdImage) Image.load(targetFilePath); | |
TextLayer txtLayer = (TextLayer) psdImage.getLayers()[1]; | |
txtLayer.getTextData().updateLayerData(); | |
PngOptions pngOptions = new PngOptions(); | |
pngOptions.setColorType(PngColorType.TruecolorWithAlpha); | |
psdImage.save(resultFilePath, pngOptions); | |
} finally { | |
if (psdImage != null) psdImage.dispose(); | |
} |