views:

64

answers:

0

I have a set of Microsoft ISF (Ink Serialized Format) images, which I am attempting to convert to PNGs to include in a web page. I have successfully used the C# package Microsoft.Ink to draw the ink to a Bitmap and save as 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);

... however, the image dimensions seem to be abnormally large. Changing the BoundingBoxMode enum passed in to the GetBoundingBox method does not appear to change anything, and I'm getting images that are 465px × 660px and contain only a handwritten letter 'a' taking up maybe 25px × 30px in actual space.

Any suggestions on how to get a more accurate bounding box?