【问题标题】:Accurate BoundingBox on Microsoft ISF?Microsoft ISF 上的准确边界框?
【发布时间】:2010-11-26 16:06:28
【问题描述】:

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

关于如何获得更准确的边界框有什么建议吗?

【问题讨论】:

    标签: c# graphics handwriting microsoft.ink


    【解决方案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);
    

    【讨论】:

      猜你喜欢
      • 2017-10-07
      • 1970-01-01
      • 1970-01-01
      • 2014-10-30
      • 2021-01-25
      • 2014-12-22
      • 2022-01-07
      • 2015-07-13
      • 2023-04-07
      相关资源
      最近更新 更多