アノテーションオブジェクトを別々のコンテナに保存するには?

文書番号 : 34201     文書種別 : 使用方法     登録日 : 2012/10/12     最終更新日 : 2015/01/07
文書を印刷する
対象製品
LEADTOOLS 17.5J Document Imaging
詳細
AnnAutomationオブジェクトを2つ用意し、それぞれのコンテナにアノテーションオブジェクトを追加することで別々に保存できます。

サンプルコード(VB.NET)
Private annAutomationManager As AnnAutomationManager
Private automation1 As AnnAutomation
Private automation2 As AnnAutomation

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  ' RasterCodecsオブジェクトを初期化します。
  Dim codecs As RasterCodecs = New RasterCodecs

  ' メイン画像をビューワにロードします。
  RasterImageViewer1.Image = codecs.Load("sample1.cmp")

  If (Not IsNothing(RasterImageViewer1.Image)) Then
    ' AutomationManagerを作成して設定します。
    annAutomationManager = New AnnAutomationManager

    ' デフォルト(すべて)の自動オブジェクトを作成します。
    annAutomationManager.CreateDefaultObjects()

    ' ツールバーを作成してフォームに追加します。
    annAutomationManager.CreateToolBar()
    Controls.Add(annAutomationManager.ToolBar)

    ' Automationを設定します(これにより、コンテナも作成されます)。
    automation1 = New AnnAutomation(annAutomationManager, RasterImageViewer1)
    automation2 = New AnnAutomation(annAutomationManager, RasterImageViewer1)

    ' このAutomationをアクティブなAutomationに設定します。
    automation1.Active = True
    automation2.Active = False
  End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  If (automation1.Active = True) Then
    automation1.Active = False
    automation1.Container.Visible = False
    automation2.Active = True
    automation2.Container.Visible = True
  Else
    automation1.Active = True
    automation1.Container.Visible = True
    automation2.Active = False
    automation2.Container.Visible = False
  End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  ' 新しいAnnCodecsクラスを作成します。
  Dim codecs As New AnnCodecs()

  ' コンテナ内のオブジェクトを保存します。
  codecs.Save("sample1_container1.ann", automation1.Container, AnnCodecsFormat.Xml, 1, AnnCodecsSavePageMode.Overwrite)
  ' コンテナ内のオブジェクトを保存します。
  codecs.Save("sample1_container2.ann", automation2.Container, AnnCodecsFormat.Xml, 1, AnnCodecsSavePageMode.Overwrite)

  ' クリアします。
  annAutomationManager.Automations.Clear()
  RasterImageViewer1.Refresh()
End Sub

サンプルコード(C#)
private AnnAutomationManager annAutomationManager; 
private AnnAutomation automation1; 
private AnnAutomation automation2; 

private void Form1_Load(object sender, EventArgs e)
{
  // RasterCodecsオブジェクトを初期化します。
  RasterCodecs codecs = new RasterCodecs();

  // メイン画像をビューワにロードします。
  rasterImageViewer1.Image = codecs.Load(@"sample1.cmp");

  if (rasterImageViewer1.Image != null)
  {
    // AutomationManagerを作成して設定します。
    annAutomationManager = new AnnAutomationManager();

    // デフォルト(すべて)の自動オブジェクトを作成します。
    annAutomationManager.CreateDefaultObjects();

    // ツールバーを作成してフォームに追加します。
    annAutomationManager.CreateToolBar();
    Controls.Add(annAutomationManager.ToolBar);

    // Automationを設定します(これにより、コンテナも作成されます)。
    automation1 = new AnnAutomation(annAutomationManager, rasterImageViewer1);
    automation2 = new AnnAutomation(annAutomationManager, rasterImageViewer1);

    // このAutomationをアクティブなAutomationに設定します。
    automation1.Active = true;
    automation2.Active = false;  
  }
}

private void button1_Click(object sender, EventArgs e)
{
  if (automation1.Active == true)
  {
    automation1.Active = false;
    automation1.Container.Visible = false;
    automation2.Active = true;
    automation2.Container.Visible = true;
  } 
  else
  {
    automation1.Active = true;
    automation1.Container.Visible = true;
    automation2.Active = false;
    automation2.Container.Visible = false;
  }
}

private void button2_Click(object sender, EventArgs e)
{
  // 新しいAnnCodecsクラスを作成します。
  AnnCodecs codecs = new AnnCodecs();

  // コンテナ内のオブジェクトを保存します。
  codecs.Save(@"sample1_container1.ann", automation1.Container, AnnCodecsFormat.Xml, 1, AnnCodecsSavePageMode.Overwrite);
  // コンテナ内のオブジェクトを保存します。
  codecs.Save(@"sample1_container2.ann", automation2.Container, AnnCodecsFormat.Xml, 1, AnnCodecsSavePageMode.Overwrite);

  // クリアします。
  annAutomationManager.Automations.Clear();
  rasterImageViewer1.Refresh();
}

実際の動作はSP1で追加された製品のチュートリアル「SaveAnnotationAnotherLayer」をご覧ください。
関連情報
キーワード
HowTo アノテーション