设置图像属性
Contents
[
Hide
]
更新字体缓存
使用 Aspose.PSD for Java,开发人员可以添加刷新字体缓存的功能。以下是所述功能的代码演示。
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
String dataDir = Utils.getDataDir(ForceFontCache.class) + "DrawingAndFormattingImages/"; | |
try (PsdImage image = (PsdImage) Image.load(dataDir + "sample.psd")) { | |
image.save(dataDir + "NoFont.psd"); | |
} | |
System.out.println("You have 2 minutes to install the font"); | |
Thread.sleep(2 * 60 * 1000); | |
OpenTypeFontsCache.updateCache(); | |
try (PsdImage image1 = (PsdImage) Image.load(dataDir + "sample.psd")) { | |
image1.save(dataDir + "HasFont.psd"); | |
} |
设置替代缺失字体
使用 Aspose.PSD for Java,开发人员可以替换缺失字体。使用下面的示例代码,开发人员将能够在将 PSD 文档保存为光栅图像(PNG、JPG 和 BMP 格式)时设置默认字体名称。该默认字体应该用作所有缺失字体的替代,即在当前操作系统中未找到的字体。以下是所述功能的代码演示。
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
String dataDir = Utils.getDataDir(FontReplacement.class) + "DrawingAndFormattingImages/"; | |
// Load an image in an instance of image and setting default replacement font. | |
PsdLoadOptions psdLoadOptions = new PsdLoadOptions(); | |
psdLoadOptions.setDefaultReplacementFont("Arial"); | |
try (PsdImage psdImage = (PsdImage) Image.load(dataDir + "Cloud_AzPlat_Banner3A_SB_EN_US_160x600_chinese_font.psd", psdLoadOptions)) { | |
PngOptions pngOptions = new PngOptions(); | |
psdImage.save(dataDir + "replaced_font.png", pngOptions); | |
} |