Web ページに含めるために PNG に変換しようとしている Microsoft ISF (Ink Serialized Format) 画像のセットがあります。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 の画像を取得していますが、実際のスペースでおそらく 25px × 30px を占める手書きの文字「a」のみが含まれています。
より正確な境界ボックスを取得する方法について何か提案はありますか?