Take the following steps to create and run a program that
implements non-automated annotations:
Start Visual Studio .NET. Choose File->New->Project… from the menu. In the New Project dialog box, choose either "Visual C# Projects" or "Visual Basic Projects" in the Projects Type List, and choose "Windows Application " in the Templates List. Type the project name as "Implementing Non Automated Annotation" in the Project Name field, and then choose OK. If desired, type a new location for your project or select a directory using the Browse button, and then choose OK . In the "Solution Explorer" window, right-click on the "References" folder, and select "Add Reference…" from the context menu. In the "Add Reference" dialog box, select the ".NET" tab and browse to Leadtools For .NET "\LEAD Technologies\LEADTOOLS 16.5\Bin\DotNet\Win32 " folder and select the following DLLs: Leadtools.dll Leadtools.Annotations.dll Leadtools.Codecs.dll Leadtools.WinForms.dll
Make sure Form1 is in design view. Go to the toolbox (View->Toolbox) and Drag and drop an instance of RasterImageViewer to the form. If you do not have RasterImageViewer in your toolbox, select Tools->Add Remove Toolbox Items from the menu. Click Browse and then select Leadtools.WinForms.DLL from "C:\Program Files (x86)\LEAD Technologies\LEADTOOLS 16.5\Bin\DotNet\Win32" and then click Open and then click OK. Change the following properties: Property Value Dock Fill Switch to Form1 code view (right-click Form1 in the solution explorer then select View Code ) and add the following lines at the beginning of the file: [Visual Basic]
[C#]Imports Leadtools Imports Leadtools.Annotations Imports Leadtools.Codecs Imports Leadtools.WinForms
using Leadtools; using Leadtools.Annotations; using Leadtools.Codecs; using Leadtools.WinForms;
Declare the following private variable: [Visual Basic]
[C#]' Annotation container object Private annContainerObj As AnnContainer
// Annotation container object private AnnContainer annContainerObj;
Add an event handler to the Form1 Load event and code it as follows: [Visual Basic]
[C#]Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' intitialize a new RasterCodecs object RasterCodecs.Startup() Dim codecs As New RasterCodecs() ' load the main image into our viewer rasterImageViewer1.Image = codecs.Load("C:\Users\Public\Documents\LEADTOOLS Images\Sample1.cmp") RasterCodecs.Shutdown() If (Not IsNothing(RasterImageViewer1.Image)) Then ' initialize the AnnContainer object and associate it with rasterImageViewer1 image annContainerObj = New AnnContainer annContainerObj.Bounds = New AnnRectangle(0, 0, RasterImageViewer1.ImageSize.Width, RasterImageViewer1.ImageSize.Height, AnnUnit.Pixel) annContainerObj.Name = "Container" annContainerObj.Visible = True annContainerObj.UnitConverter = New AnnUnitConverter(96, 96) ' create Annotation Note Object and add it to the container annContainerObj.Objects.Add(CreateAnnNoteObject(New AnnRectangle(annContainerObj.Bounds.Right / 2, annContainerObj.Bounds.Bottom / 2, (annContainerObj.Bounds.Right / 4) - 1, (annContainerObj.Bounds.Bottom / 4) - 1))) End If End Sub
private void Form1_Load(object sender, System.EventArgs e) { // intitialize a new RasterCodecs object RasterCodecs.Startup(); RasterCodecs codecs = new RasterCodecs(); // load the main image into our viewer rasterImageViewer1.Image = codecs.Load(@"C:\Users\Public\Documents\LEADTOOLS Images\Sample1.cmp"); RasterCodecs.Shutdown(); if(rasterImageViewer1.Image != null) { // initialize the AnnContainer object and associate it with rasterImageViewer1 image annContainerObj = new AnnContainer(); annContainerObj.Bounds = new AnnRectangle(0, 0, rasterImageViewer1.ImageSize.Width, rasterImageViewer1.ImageSize.Height, AnnUnit.Pixel); annContainerObj.Name = "Container"; annContainerObj.Visible = true; annContainerObj.UnitConverter = new AnnUnitConverter(96, 96); // create Annotation Note Object and add it to the container annContainerObj.Objects.Add(CreateAnnNoteObject(new AnnRectangle(annContainerObj.Bounds.Right/2, annContainerObj.Bounds.Bottom/2, (annContainerObj.Bounds.Right/4) - 1, (annContainerObj.Bounds.Bottom/4) - 1))); } }
Add an event handler to the rasterImageViewer1 TransformChanged event and code it as follows: [Visual Basic]
[C#]Private Sub RasterImageViewer1_TransformChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RasterImageViewer1.TransformChanged If (Not IsNothing(annContainerObj)) Then annContainerObj.Transform = RasterImageViewer1.Transform.Clone() End If End Sub
private void rasterImageViewer1_TransformChanged(object sender, System.EventArgs e) { if(annContainerObj != null) annContainerObj.Transform = rasterImageViewer1.Transform.Clone(); }
Add an event handler to the rasterImageViewer1 PostImagePaint event and code it as follows: [Visual Basic]
[C#]Private Sub RasterImageViewer1_PostImagePaint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles RasterImageViewer1.PostImagePaint If (Not IsNothing(annContainerObj)) Then annContainerObj.Draw(e.Graphics) End If End Sub
private void rasterImageViewer1_PostImagePaint(object sender, System.Windows.Forms.PaintEventArgs e) { if(annContainerObj != null) annContainerObj.Draw(e.Graphics); }
Add the CreateAnnNoteObject function code to class Form1: [Visual Basic]
[C#]Private Function CreateAnnNoteObject(ByVal boundingRect As AnnRectangle) As AnnObject Dim annNoteObj As AnnNoteObject = New AnnNoteObject annNoteObj.Text = "This is my Text" annNoteObj.TextColor = Color.FromArgb(255, 0, 0) annNoteObj.Pen = New AnnPen(Color.Red, New AnnLength(3)) annNoteObj.Brush = New AnnSolidBrush(Color.Yellow) annNoteObj.Font = New AnnFont(New FontFamily("Arial"), New AnnLength(14), FontStyle.Bold) annNoteObj.Hyperlink = "Notepad.exe" annNoteObj.Bounds = boundingRect Return annNoteObj End Function
private AnnObject CreateAnnNoteObject( AnnRectangle boundingRect) { AnnNoteObject annNoteObj = new AnnNoteObject(); annNoteObj.Text = "This is my Text"; annNoteObj.TextColor = Color.FromArgb(255, 0, 0); annNoteObj.Pen = new AnnPen(Color.Red , new AnnLength(3)); annNoteObj.Brush = new AnnSolidBrush(Color.Yellow); annNoteObj.Font = new AnnFont(new FontFamily("Arial"), new AnnLength(14), FontStyle.Bold); annNoteObj.Hyperlink = "Notepad.exe"; annNoteObj.Bounds = boundingRect; return annNoteObj; }
Build, and Run the program to test it.