0

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」のみが含まれています。

より正確な境界ボックスを取得する方法について何か提案はありますか?

4

1 に答える 1

1

境界ボックスの四角形は "Inkspace" 座標にあります - 使い捨てのビットマップとグラフィック オブジェクトを作成し、renderer.InkSpacetoPixel を使用して四角形を変換します。

GetBoundingBox 呼び出しとビットマップ bm の作成の間に次の行を追加すると、ビットマップのサイズが正しくなります。

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 に答える