AccuSoft Resource Center
ImageGear DLL 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 DLL library. This tutorial uses Microsoft® Visual C++® 6.0 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 C++ 6.0 and ImageGear v14.
Preparing the Compiler
- To create the application interface, start Visual C++. The
Visual C++ environment will appear.
- Create a new MFC AppWizard project. For this tutorial, the
project will be called IGTutorial (see below.)
- In the MFC AppWizard – Step 1 dialog, click Single
document to specify the type of application being created (see
below).

- Once the application is created, set up the compiler to use ImageGear.
- From the Project menu, click Settings
- In the Project Settings dialog, click the C/C++ tab
- From the Category drop-down list, select Preprocessor
- In the Additional include directories text box, type the path to where ImageGear was installed—the default path is C:\Program Files\AccuSoft\ImageGear v14\Version\DLL\Include, where Version is the edition of ImageGear (Professional, Enterprise or MD) being used (see below).
Next, click the Link tab. From the Category drop-down list, click Input and make the following additional changes:
- In the Object/library modules text box, type igcore14d.lib
- In the Additional library path text box, type C:\Program Files\Accusoft\ImageGear v14\Version\DLL\Lib, where Version is the edition of ImageGear (Professional, Enterprise or MD) being used
- Add Zoom In and Zoom Out items to the View menu. For this
tutorial, the IDs for these two items are ID_ZIN and ID_ZOUT
respectively (see below).

Add the Code
- Add the ImageGear header-file #include statement and add a
member to the CIGTutorialDoc class, by modifying the
IGTutorialDoc.h file (add the lines shown in bold):
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "gear.h"
class CIGTutorialDoc : public CDocument
{
protected: // create from serialization only
CIGTutorialDoc();
DECLARE_DYNCREATE(CIGTutorialDoc)
// Attributes
public:
HIGEAR hIGear;
// Operations
public:
This provides access to the ImageGear functions for use in our application. It also creates an ImageGear handle that will be used to hold the image it loaded and will be passed to the different ImageGear functions that are called.
- Next, add code to the constructor and destructor of the
CIGTutorial class, by modifying the IGTutorialDoc.cpp
file (add the lines shown in bold):
/////////////////////////////////////////////////////////////////////////////
// CIGTutorialDoc construction/destruction
CIGTutorialDoc::CIGTutorialDoc()
:hIGear(NULL)
{
// TODO: add one-time construction code here
}
CIGTutorialDoc::~CIGTutorialDoc()
{
if (IG_image_is_valid( hIGear ))
IG_image_delete( hIGear );
}
The code above includes the following ImageGear functions:
| IG_image_is_valid | This function is called to determine if the HIGEAR variable hIGear contains a handle of a valid ImageGear image. | |
| IG_image_delete | This function removes the HIGEAR handle of hIGear and frees the memory of the associated HIGEAR function. The function also frees the memory associated with the image’s DIB, if ImageGear allocated the DIB memory. If not, the DIB continues to exist and it becomes the responsibility of your application to free this memory when it is no longer required. |
- Use the Wizard Bar to add a virtual function named
OnOpenDocument to the CIGTutorialDoc class. Replace the
TODO
comment with the following code in that function (add the
lines shown in bold):
/////////////////////////////////////////////////////////////////////////////
// CIGTutorialDoc commands
BOOL CIGTutorialDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;
if ( IG_load_file( (char*) lpszPathName, &hIGear ) == 0 )
return TRUE;
else
{
// ErrorReport should go here
return FALSE;
}
}
The code above includes the following ImageGear function:
| IG_load_file | This function loads the specified file into the HIGEAR. |
- Use the Wizard Bar to add three public member functions to
the CIGTutorialDoc class. The code for the three functions is
as follows (add the lines shown in bold):
AT_ERRCOUNT CIGTutorialDoc::dsplZoomSet(CView *v, AT_MODE nZoomMode, DOUBLE dHZoom, DOUBLE dVZoom)
{
DWORD dwGrpID = 0;
AT_ERRCOUNT nErrCount;
nErrCount = IG_dspl_zoom_set( hIGear, dwGrpID, nZoomMode, dHZoom, dVZoom );
if ( nErrCount != NULL )
{
// ErrorReport should go here
}
return nErrCount;
}
AT_ERRCOUNT CIGTutorialDoc::dsplZoomGet(CView *v, LPAT_MODE lpnZoomMode, LPDOUBLE lpdHZoom, LPDOUBLE lpdVZoom)
{
DWORD dwGrpID = 0;
AT_ERRCOUNT nErrCount;
nErrCount = IG_dspl_zoom_get( hIGear, dwGrpID, v->GetSafeHwnd(), lpnZoomMode, lpdHZoom, lpdVZoom );
if ( nErrCount != NULL )
{
// ErrorReport should go here
}
return nErrCount;
}
void CIGTutorialDoc::DrawImage(CView *v, CDC *dc, CPrintInfo *pInfo)
{
if ( IG_image_is_valid( hIGear ))
{
DWORD dwGrpID = 0;
POINT p;
SIZE s;
DWORD nMapMode;
AT_RECTANGLE Viewport;
AT_RECTANGLE Window;
// get current mapping parameters
nMapMode = ::GetMapMode( dc->m_hDC );
::GetViewportOrgEx( dc->m_hDC, &p );
Viewport.x = p.x;
Viewport.y = p.y;
::GetViewportExtEx( dc->m_hDC, &s );
Viewport.width = s.cx;
Viewport.height = s.cy;
::GetWindowOrgEx( dc->m_hDC, &p );
Window.x = p.x;
Window.y = p.y;
::GetWindowExtEx( dc->m_hDC, &s );
Window.width = s.cx;
Window.height = s.cy;
IG_dspl_mapmode_set( hIGear, dwGrpID,
nMapMode, &Viewport, &Window );
IG_dspl_image_draw( hIGear, dwGrpID,
v->GetSafeHwnd(), dc->GetSafeHdc(), NULL );
}
}
The code above includes the following ImageGear functions:
| IG_dspl_mapmode_set | This function sets the current map mode and logical coordinate system. | |
| IG_dspl_image_draw | This function draws and image onto a destination device context. | |
| IG_dspl_zoom_set | This function sets the current zoom value. | |
| IG_dspl_zoom_get | This function gets the current zoom value. |
- Next, add the following code to the OnDraw() method of the
CIGTutorialView class (add the lines shown in bold):
/////////////////////////////////////////////////////////////////////////////
// CIGTutorialView drawing
void CIGTutorialView::OnDraw(CDC* pDC)
{
CIGTutorialDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
pDoc->DrawImage( this, pDC, NULL );
}
The above code calls the DrawImage function defined in IGTutorialDoc.cpp and ensures that the image will be properly drawn when the window is redrawn.
Use the Wizard Bar to add command message handlers for the ID_ZIN and ID_ZOUT messages to CIGTutorialView. Then, add the following code to the message handler functions (add the lines shown in bold):
/////////////////////////////////////////////////////////////////////////////
// CIGTutorialView message handlers
void CIGTutorialView::OnZin()
{
DOUBLE dHZoom, dVZoom;
CIGTutorialDoc* pDoc = GetDocument();
ASSERT_VALID( pDoc );
pDoc->dsplZoomGet( this, NULL, &dHZoom ,&dVZoom );
dHZoom *= 1.25;
dVZoom *= 1.25;
pDoc->dsplZoomSet( this,
IG_DSPL_ZOOM_H_FIXED | IG_DSPL_ZOOM_V_FIXED, dHZoom, dVZoom );
InvalidateRect( NULL, FALSE );
UpdateWindow();
}
void CIGTutorialView::OnZout()
{
DOUBLE dHZoom, dVZoom;
CIGTutorialDoc* pDoc = GetDocument();
ASSERT_VALID( pDoc );
pDoc->dsplZoomGet( this, NULL, &dHZoom ,&dVZoom );
dHZoom /= 1.25;
dVZoom /= 1.25;
pDoc->dsplZoomSet( this,
IG_DSPL_ZOOM_H_FIXED | IG_DSPL_ZOOM_V_FIXED, dHZoom, dVZoom );
InvalidateRect( NULL, FALSE );
UpdateWindow();
}
The code above zooms in and out respectfully, increasing/decreasing the image size in increments of 25%.
- Finally, add the following code to the InitInstance()
method of the CIGTutorialApp class (add the line shown in
bold):
/////////////////////////////////////////////////////////////////////////////
// CIGTutorialApp initialization
BOOL CIGTutorialApp::InitInstance()
{
AfxEnableControlContainer();
.
.
.
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
IG_lic_solution_name_set( "AccuSoft 1-100-14" );
// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}
Running the Application
That's it! Simply compile and run the DLL project and you will have a simple, yet functional image viewer. Add the plug-ins to enable support for over 100 image formats.


