選択しているアノテーションオブジェクトのみを画像に描画するには?
対象製品
LEADTOOLS 17.5J Document Imaging
詳細
選択していないアノテーションオブジェクトのVisibleプロパティをfalseに設定して非表示にしてからRealizeメソッドを実行すれば実現できます。
サンプルコード(VB.NET)
サンプルコード(C#)
実際の動作はSP1で追加された製品のチュートリアル「RealizeOnlySelectedAnnotation」をご覧ください。
サンプルコード(VB.NET)
' 自動モードの管理に使用するAutomationManager Private annAutomationManager As AnnAutomationManager 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を設定します(これにより、コンテナも作成されます)。 Dim automation As AnnAutomation = New AnnAutomation(annAutomationManager, RasterImageViewer1) ' このAutomationをアクティブなAutomationに設定します。 automation.Active = True End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim automation As AnnAutomation = annAutomationManager.Automations.Item(0) ' 選択中のオブジェクト以外を非表示にします。 For i As Integer = 0 To automation.Container.Objects.Count - 1 If automation.Container.Objects(i) IsNot automation.CurrentEditObject Then automation.Container.Objects(i).Visible = False End If Next annAutomationManager.Automations.Item(0).Realize() ' 反映後、非表示のオブジェクトを表示にします。 For i As Integer = 0 To automation.Container.Objects.Count - 1 If automation.Container.Objects(i).Visible = False Then automation.Container.Objects(i).Visible = True End If Next End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ' RasterCodecsオブジェクトを初期化します。 Dim codecs As RasterCodecs = New RasterCodecs ' 保存します。 codecs.Save(RasterImageViewer1.Image, "Result.png", RasterImageFormat.Png, 0) End Sub
サンプルコード(C#)
// 自動モードの管理に使用するAutomationManager private AnnAutomationManager annAutomationManager; 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を設定します(これにより、コンテナも作成されます)。 AnnAutomation automation = new AnnAutomation(annAutomationManager, rasterImageViewer1); // このAutomationをアクティブなAutomationに設定します。 automation.Active = true; } } private void button1_Click(object sender, EventArgs e) { // Automationを設定します(これにより、コンテナも作成されます)。 AnnAutomation automation = annAutomationManager.Automations[0]; // 選択中のオブジェクト以外を非表示にします。 for (int i = 0; i <= automation.Container.Objects.Count - 1; i++) { if (!object.ReferenceEquals(automation.Container.Objects[i], automation.CurrentEditObject)) { automation.Container.Objects[i].Visible = false; } } annAutomationManager.Automations[0].Realize(); // 反映後、非表示のオブジェクトを表示にします。 for (int i = 0; i <= automation.Container.Objects.Count - 1; i++) { if (automation.Container.Objects[i].Visible == false) { automation.Container.Objects[i].Visible = true; } } } private void button2_Click(object sender, EventArgs e) { // RasterCodecsオブジェクトを初期化します。 RasterCodecs codecs = new RasterCodecs(); // 保存します。 codecs.Save(rasterImageViewer1.Image, @"Result.png", RasterImageFormat.Png, 0); }
実際の動作はSP1で追加された製品のチュートリアル「RealizeOnlySelectedAnnotation」をご覧ください。
関連情報
- アノテーションオブジェクトのサイズを指定して追加するには?
- アノテーションオブジェクトを別々のコンテナに保存するには?
- 非自動アノテーションオブジェクトを画像に描画するには?
- アノテーションの削除を検知できるイベントはありますか?
キーワード
HowTo アノテーション