Delegate CustomFontSource
Delegate CustomFontSource
Namespace: Aspose.Imaging
Assembly: Aspose.Imaging.dll (25.2.0)
ฟังก์ชันผู้ให้บริการแหล่งฟอนต์แบบกำหนดเอง
public delegate CustomFontData[] CustomFontSource(params object[] args)
พารามิเตอร์
args
object[]
อาร์กิวเมนต์ต่างๆ
คืนค่า
รายการฟอนต์เฉพาะสำหรับการเรนเดอร์ภาพ
ตัวอย่าง
ตัวอย่างนี้แสดงให้เห็นถึงการให้บริการแหล่งฟอนต์แบบกำหนดเองเพื่อใช้ฟอนต์เฉพาะสำหรับการเรนเดอร์ภาพ แตกต่างจากวิธี FontSettings.SetFontsFolders ที่ทำงานในขอบเขตของภาพและอนุญาตให้จัดเตรียมฟอนต์ในสถานการณ์ที่มีผู้ใช้หลายคน ```csharp [C#]
public void CustomFontSourceTest(string inputPath, string outputPath, string fileName, string fontPath)
{
var loadOptions = new Aspose.Imaging.LoadOptions();
loadOptions.AddCustomFontSource(GetFontSource, fontPath);
using (var img = Image.Load(System.IO.Path.Combine(inputPath, fileName), loadOptions))
{
Aspose.Imaging.ImageOptions.VectorRasterizationOptions vectorRasterizationOptions =
(Aspose.Imaging.ImageOptions.VectorRasterizationOptions)img.GetDefaultOptions(new object[] { Color.White, img.Width, img.Height });
vectorRasterizationOptions.TextRenderingHint = Aspose.Imaging.TextRenderingHint.SingleBitPerPixel;
vectorRasterizationOptions.SmoothingMode = Aspose.Imaging.SmoothingMode.None;
img.Save(System.IO.Path.Combine(outputPath, fileName + ".png"), new Aspose.Imaging.ImageOptions.PngOptions
{
VectorRasterizationOptions = vectorRasterizationOptions
});
}
}
// ตัวอย่างผู้ให้บริการฟอนต์แบบกำหนดเอง
private Aspose.Imaging.CustomFontHandler.CustomFontData[] GetFontSource(params object[] args)
{
string fontsPath = string.Empty;
if (args.Length > 0)
{
fontsPath = args[0].ToString();
}
var customFontData = new System.Collections.Generic.List<aspose.imaging.customfonthandler.customfontdata>();
foreach (var font in System.IO.Directory.GetFiles(fontsPath))
{
customFontData.Add(new Aspose.Imaging.CustomFontHandler.CustomFontData(Path.GetFileNameWithoutExtension(font), System.IO.File.ReadAllBytes(font)));
}
return customFontData.ToArray();
}</aspose.imaging.customfonthandler.customfontdata>