设置图像属性

更新字体缓存

使用 Aspose.PSD for .NET,开发人员可以添加刷新字体缓存的功能。以下是所述功能的代码演示。

// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET
using (PsdImage image = (PsdImage)Image.Load(dataDir + "sample.psd"))
{
image.Save("NoFont.psd");
}
Console.WriteLine("You have 2 minutes to install the font");
Thread.Sleep(TimeSpan.FromMinutes(2));
OpenTypeFontsCache.UpdateCache();
using (PsdImage image = (PsdImage)Image.Load(dataDir + @"sample.psd"))
{
image.Save(dataDir + "HasFont.psd");
}

设置缺失字体的替代品

使用 Aspose.PSD for .NET,开发人员可以替换缺失的字体。使用下面的示例代码,开发人员将能够在将 PSD 文档保存为光栅图像(PNG、JPG 和 BMP 格式)时设置默认字体名称。这个默认字体应该用作所有缺失字体的替代,即在当前操作系统中找不到的字体。以下是所述功能的代码演示。

// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET
string sourceFileName = "sample_konstanting.psd";
string[] outputs = new string[]
{
"replacedfont0.tiff",
"replacedfont1.png",
"replacedfont2.jpg"
};
using (PsdImage image = (PsdImage)Image.Load(sourceFileName, new PsdLoadOptions()))
{
// This way you can use different fonts for different outputs
image.Save(outputs[0], new TiffOptions(TiffExpectedFormat.TiffJpegRgb) { DefaultReplacementFont = "Arial" });
image.Save(outputs[1], new PngOptions { DefaultReplacementFont = "Verdana" });
image.Save(outputs[2], new JpegOptions { DefaultReplacementFont = "Times New Roman" });
}