ImageGear for .NET
Developing the Application
Send Feedback
ImageGear for .NET User Guide > Getting Started > ImageGear for .NET Visual Studio 2010 Tutorials > ImageGear for .NET VB.NET Tutorial > Developing the Application

Glossary Item Box

  1. First, add the necessary Imports statements.
    1. Open the code for the form by right-clicking on the form and clicking View Code.
    2. At the top of the code, add the following statements:
      VB .NET Copy Code
      Imports System.IO
      Imports System.Diagnostics
      Imports ImageGear
      Imports ImageGear.Core
      Imports ImageGear.Windows.Forms
      Imports ImageGear.Display
      Imports ImageGear.Processing
      Imports ImageGear.Formats
  2. Next, add the following member variables to Form1: 
    VB .NET Copy Code
    ' holds the image data 
    Private igPage As ImGearPage
    ' controls how the page is displayed 
    Private igPageDisplay As ImGearPageDisplay
  3. If you are using a Deployment (Runtime) licensing, add the license initialization code to the Form1 constructor(Form1()) just before the call to InitializeComponent. This is not necessary if you are using an Evaluation or Development (Toolkit) license.
    VB .NET Copy Code
    '***The SetSolutionName, SetSolutionKey and possibly the SetOEMLicenseKey 
    'methods must be called to distribute the runtime.***
    'ImGearLicense.SetSolutionName("YourSolutionName")
    'ImGearLicense.SetSolutionKey(12345, 12345, 12345, 12345)
    'Manually Reported Runtime licenses also require the following method 
    'call to SetOEMLicenseKey. 
    'ImGearLicense.SetOEMLicenseKey("2.0.AStringForOEMLicensing...");
Please add the ImGearEvaluationManager.Initialize() call if you are evaluating the product.
  1. Below the code from the prior step, add the following calls to initialize the referenced formats:
    VB .NET Copy Code
    ' Support for common formats:
    ImGearCommonFormats.Initialize()
  2. Now add the following code to the Load Page menu handler.
    VB .NET Copy Code
    LoadPageToolStripMenuItem.Click
    Dim dlg As New OpenFileDialog
    dlg.Filter = "All files (*.*)|*.*"
    dlg.FilterIndex = 1
    dlg.RestoreDirectory = True
    If dlg.ShowDialog = DialogResult.OK Then
    Dim stream As New FileStream(dlg.FileName, FileMode.Open,    FileAccess.Read)
    Try
      ' load the image into the page 
      igPage = ImGearFileFormats.LoadPage(stream, 0)
    Catch ex As Exception
                    Console.WriteLine("Failed to load image")
    End Try
    If Not igPage Is Nothing AndAlso Not igPage.DIB Is Nothing Then
            ' create a new page display 
            igPageDisplay = New ImGearPageDisplay(igPage)
            ' associate the page display with the page view 
             ImGearPageView1.Display = igPageDisplay
            ' cause the page view to repaint 
             ImGearPageView1.Invalidate()
                End If
            End If
        End Sub
    The code above utilizes:
    ImGearPageDisplay Class Constructs a new PageDisplay object for the given page.
    ImGearPageView.Invalidate Invalidates the control thus causing it to repaint.
    ImGearFileFormats.LoadPage Method Loads a file from a given stream and returns a new ImGearPage Class.
    ImGearFileFormats.GetSavingFilter Method Gets a filter string which can be passed to a windows common dialog filter member.
  3. Now go to the handler created for the Zoom In menu item. Add the following code to the routine:
    VB .NET Copy Code
    If Not igPageDisplay Is Nothing AndAlso Not igPageDisplay.Page.DIB.IsEmpty() Then
       ' get the current zoom info 
       Dim igZoomInfo As ImGearZoomInfo
       igZoomInfo = igPageDisplay.GetZoomInfo(ImGearPageView1)
       ' increase the zoom 
       igZoomInfo.Horizontal.Value = igZoomInfo.Horizontal.Value * 1.25
       igZoomInfo.Vertical.Value = igZoomInfo.Vertical.Value * 1.25
       igZoomInfo.Horizontal.Fixed = True
       igZoomInfo.Vertical.Fixed = True
       ' set the new zoom values and repaint the view 
       igPageDisplay.UpdateZoomFrom(igZoomInfo)
       ImGearPageView1.Invalidate()
    End If
    The code above utilizes:
    ImGearPageDisplay.GetZoomInfo Method Retrieves the current zoom information from the display and page view.
    ImGearPageDisplay.UpdateZoomFrom Method Sets new zoom values from the given ImGearZoomInfo Structure object.
    ImGearZoomInfo Structure Holds horizontal and vertical zoom values and settings.
  4. Add the following code to the Zoom Out click handler:
    VB .NET Copy Code
    If Not igPageDisplay Is Nothing AndAlso Not igPageDisplay.Page.DIB.IsEmpty() Then
        ' get the current zoom info 
        Dim igZoomInfo As ImGearZoomInfo
        igZoomInfo = igPageDisplay.GetZoomInfo(ImGearPageView1)
        ' decrease the zoom 
        igZoomInfo.Horizontal.Value = igZoomInfo.Horizontal.Value / 1.25
        igZoomInfo.Vertical.Value = igZoomInfo.Vertical.Value / 1.25
        igZoomInfo.Horizontal.Fixed = True
        igZoomInfo.Vertical.Fixed = True
        ' set the new zoom values and repaint the view 
        igPageDisplay.UpdateZoomFrom(igZoomInfo)
        ImGearPageView1.Invalidate()
    End If
  5. Add the code below to the Rotate 90 click handler.
    Example Title Copy Code
    If Not igPage Is Nothing Then
       Try
          ImGearProcessing.Rotate(igPage, ImGearRotationValues.VALUE_90)
       Catch ex As Exception
          Console.WriteLine(ex.Message)
       End Try
          ImGearPageView1.Invalidate()
    End If
    The code above utilizes:
    ImGearProcessing.Rotate Method Rotates the given page by the given amount.
  6. The code for the click handlers for the Rotate 180 and Rotate 270 menu items are the same as above except that the amount to rotate by is ImGearRotationValues.VALUE_180 and ImGearRotationValues.VALUE_270, respectively.
  7. Lastly, add the click code for the Exit menu item as shown below:
    VB .NET Copy Code
    Application.Exit()
  8. And now you're ready to compile and run the finished application.
©2013. Accusoft Corporation. All Rights Reserved.