0

我有一组 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。

关于如何获得更准确的边界框的任何建议?

4

1 回答 1

1

边界框矩形位于“Inkspace”坐标中 - 创建一次性位图和图形对象,然后使用 renderer.InkSpacetoPixel 转换矩形。

在 GetBoundingBox 调用和 Bitmap bm 的创建之间添加这些行,并且 Bitmap 的大小应该正确:

Bitmap bmTrash = new Bitmap(10, 10);
Graphics gTrash = Graphics.FromImage(bmTrash);
renderer.InkSpaceToPixel(gTrash, rect.Location);
renderer.InkSpaceToPixel(gTrash, rect.Size);
于 2010-12-09T17:53:27.163 回答