Hiển thị văn bản với màu sắc khác nhau trong Lớp Văn bản
Contents
[
Hide
]
Hiển thị văn bản với màu sắc khác nhau trong Lớp Văn bản
Aspose.PSD hỗ trợ chuyển đổi các tệp PSD thành hình ảnh. Có thể có trường hợp văn bản trong tệp PSD chứa các màu sắc khác nhau. Aspose.PSD hỗ trợ chuyển đổi các tệp PSD như vậy thành hình ảnh.
Đoạn mã sau minh họa việc chuyển đổi một tệp PSD với các màu sắc khác nhau trong Lớp Văn bản thành PNG
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 | |
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(); | |
} |