AccuSoft Resource Center
ImageGear ActiveX Tutorial
ImageGear is the industry standard for imaging application development. Building your application with our award-winning toolkits provides you with a powerful set of imaging libraries and image manipulation features and functions. In this tutorial, you will create an application using the ImageGear ActiveX control. This tutorial uses Microsoft® Visual Basic® 6.0 SP6 and assumes that you are using Microsoft Windows 98SE, Me, 2000 or XP. The application you create will load, display and zoom images. The instructions for this tutorial are specific to Microsoft Visual Basic 6.0 and ImageGear v14.
Preparing the Compiler
- To create the application interface, start Visual Basic.
From the New Project window, select the Standard EXE icon and click Open (see
below).

- Once the project is created you should add the ImageGear ActiveX controls to the project. From the Project menu, select Components to access the list of available controls. Check off the following components:
AccuSoft ImageGear 14 Core Library
AccuSoft ImageGear 14 Dialogs Library
AccuSoft ImageGear 14 Display Library
AccuSoft ImageGear 14 Formats Library
AccuSoft ImageGear 14 View Library
Note: If you do not see a required control in the list, you may need to install the ImageGear ActiveX product. If you selected to install this product on first use, simply run one of the ImageGear ActiveX samples. To do this, click Start, Programs, AccuSoft, ImageGear v14, ActiveX, Samples to locate the samples. Launching an ImageGear sample program will automatically cause the ActiveX product to be downloaded and installed on your machine.
![]()
Once you click OK you will see the icons for the ImageGear controls appear in the Controls toolbar (see below).
Setting up the Form
- From the Tools menu, select Menu Editor. The Menu
Editor dialog box will be displayed.
- Add three menu items to the form with the following characteristics:
| Caption Open Zoom In Zoom Out |
Name mnuOpen mnuZoomin mnuZoomout |
- In turn, add each ImageGear control to the form by clicking the appropriate icon in the toolbox and drawing the control on the form. Stretch the PageView control (IGPageViewCtl) to fill most of the form; it should appear as a white rectangle. The remaining controls (IGCoreCtl, IGDisplayCtl, IGFormatsCtl and IGDlgsCtl) should show up as small icons on the form. For this tutorial we will use the default names (e.g. IGCoreCtl1) for each control. Your form should now look something like this:
Add the Code
- Add the following form declarations and subroutines for
Form_Load and Form_Resize:
Private currentPage As IGPage
Private currentPageDisp As IGPageDisplay
Private currentFileDialog As IGFileDlg
Private Sub Form_Load()
On Error GoTo ErrorHandler
IGCoreCtl1.License.SetSolutionName "AccuSoft 1-100-14"
IGCoreCtl1.Result.NotificationFlags = IG_ERR_OLE_ERROR
IGCoreCtl1.AssociateComponent IGFormatsCtl1.ComponentInterface
IGCoreCtl1.AssociateComponent IGDisplayCtl1.ComponentInterface
IGCoreCtl1.AssociateComponent IGProcessingCtl1.ComponentInterface
IGDlgsCtl1.GearFormats = IGFormatsCtl1.ComponentInterface
IGDlgsCtl1.GearCore = IGCoreCtl1.ComponentInterface
IGDlgsCtl1.GearDisplay = IGDisplayCtl1.ComponentInterface
Set currentFileDialog = IGDlgsCtl1.CreateFileDlg
Set currentPage = IGCoreCtl1.CreatePage
Set currentPageDisp = IGDisplayCtl1.CreatePageDisplay(currentPage)
IGPageViewCtl1.PageDisplay = currentPageDisp
IGPageViewCtl1.UpdateView
Exit Sub
ErrorHandler:
MsgBox "Errors on stack? " & IGCoreCtl1.Result.isOk & vbCrLf & _
Err.Description, vbCritical, "An error has occured"
End Sub
Private Sub Form_Resize()
If Me.Height > 0 Then
IGPageViewCtl1.Height = Me.ScaleHeight
End If
If Me.Width > 0 Then
IGPageViewCtl1.Width = Me.ScaleWidth
End If
End Sub
The code above includes the following ImageGear methods and properties:
| IGCoreCtl | License.SetSolutionName | This method of the IGLicense object sets the solution name for the ImageGear license. | |
| Result.NotificationFlag | This method of the IGResult object tells ImageGear to report errors using the VB ON Error mechanism. | ||
| AssociateComponent | This method associates ImageGear components with the Core control. | ||
| CreatePage | This method creates and returns a new IGPage object. | ||
| Result.isOk | This property of the IGResult object tells if there are any errors on the error stack. | ||
| IGDlgsCtl | GearFormats | This property sets the current Formats control used by the Dialog control. | |
| GearCore | This property sets the current Core control used by the Dialog control. | ||
| IGDisplayCtl | CreatePageDisplay | This method creates a new IGPageDisplay object for the specified IGPage. | |
| IGPageViewCtl | PageDisplay | This property sets the current Page Display object displayed by the Page View control. | |
| UpdateView | This method causes the Page View control to redraw itself. |
- Next, create a click procedure for mnuOpen
by clicking the menu on the form or by copying the code below:
Private Sub mnuOpen_Click()
On Error GoTo ErrorHandler
Dim loadDialogOptions As IGFileDlgPageLoadOptions
Set loadDialogOptions = _
IGDlgsCtl1.CreateFileDlgOptions(IG_FILEDLGOPTIONS_PAGELOADOBJ)
If currentFileDialog.Show(loadDialogOptions) Then
IGFormatsCtl1.LoadPageFromFile currentPage, loadDialogOptions.FileName, _
loadDialogOptions.PageNum
End If
IGPageViewCtl1.UpdateView
Exit Sub
ErrorHandler:
MsgBox "Errors on stack? " & IGCoreCtl1.Result.isOk & vbCrLf & _
Err.Description, vbCritical, "An error has occured"
End Sub
The code above includes the following methods:
| IGDlgsCtl | CreateFileDlgOptions | This method creates a file dialog options object that will contain for example the filename and page number. | |
| IGFileDlg | Show | This method shows the file dialog and returns True if the user clicked OK. | |
| IGFormatsCtl | LoadPageFromFile | This method loads an image into the specified IGPage from the specified filename. |
- Finally, add click procedures for the mnuZoomin and
mnuZoomout commands by double-clicking on each control
respectively, or by copying the code below:
Private Sub mnuZoomIn_Click()
On Error GoTo ErrorHandler
Dim zoomzoom As IGDisplayZoomInfo
Set zoomzoom = currentPageDisp.GetZoomInfo(IGPageViewCtl1.hWnd)
zoomzoom.HZoom = zoomzoom.HZoom * 1.25
zoomzoom.VZoom = zoomzoom.VZoom * 1.25
zoomzoom.Mode = IG_DSPL_ZOOM_H_FIXED Or IG_DSPL_ZOOM_V_FIXED
currentPageDisp.UpdateZoomFrom zoomzoom
IGPageViewCtl1.UpdateView
Exit Sub
ErrorHandler:
MsgBox "Errors on stack? " & IGCoreCtl1.Result.isOk & vbCrLf & _
Err.Description, vbCritical, "An error has occured"
End Sub
The above code zooms the image to 125 percent, or 5/4ths, of its size (zoom in by 25 percent).
Private Sub mnuZoomOut_Click()
On Error GoTo ErrorHandler
Dim zoomzoom As IGDisplayZoomInfo
Set zoomzoom = currentPageDisp.GetZoomInfo(IGPageViewCtl1.hWnd)
zoomzoom.HZoom = zoomzoom.HZoom * 0.8
zoomzoom.VZoom = zoomzoom.VZoom * 0.8
zoomzoom.Mode = IG_DSPL_ZOOM_H_FIXED Or IG_DSPL_ZOOM_V_FIXED
currentPageDisp.UpdateZoomFrom zoomzoom
IGPageViewCtl1.UpdateView
Exit Sub
ErrorHandler:
MsgBox "Errors on stack? " & IGCoreCtl1.Result.isOk & vbCrLf & _
Err.Description, vbCritical, "An error has occured"
End Sub
The above code zooms out, decreasing the image to 4/5ths of its size, thereby canceling the effect of the zoom-in above.
The code above includes:
| IGPageDisplay | GetZoomInfo | This method creates and returns a new IGDisplayZoomInfo object that contains zoom mode and values. | |
| UpdateZoomFrom | This method sets zoom mode and values from the specified IGDisplayZoomInfo object. |
Running the Application
That's it! Simply compile and run the ActiveX project and you will have a simple, yet functional image viewer. Add the plug-ins to enable support for over 100 image formats.



