我有一组 Microsoft ISF(墨水序列化格式)图像,我正在尝试将其转换为 PNG 以包含在网页中。我已成功使用 C# 包 Microsoft.Ink 将墨迹绘制到位图并另存为 PNG:
byte[] data; // data has the raw bytes of the ISF file
Ink ink = new Ink();
Renderer renderer = new Renderer();
Stream outStream; // a Stream to hold the PNG data
ink.Load(data);
using (Strokes strokes = ink.Strokes) {
// get bounds of ISF
rect = strokes.GetBoundingBox(BoundingBoxMode.PointsOnly);
// create bitmap matching bounds
bm = new Bitmap(rect.Width, rect.Height);
// draw the ISF onto the Bitmap
using (Graphics g = Graphics.FromImage(bm)) {
g.Clear(Color.Transparent);
renderer.Draw(g, strokes);
}
}
// save the Bitmap to PNG format
bm.Save(outStream, System.Drawing.Imaging.ImageFormat.Png);
...但是,图像尺寸似乎异常大。更改传递给 GetBoundingBox 方法的 BoundingBoxMode 枚举似乎并没有改变任何东西,我得到的图像是 465px × 660px 并且只包含一个手写字母“a”,在实际空间中可能占据 25px × 30px。
关于如何获得更准确的边界框的任何建议?