ImageMan ActiveX
Using the hDIB and hImage Properties

The hDIB property allows the image control to export and import memory based images.


By querying the hDIB property you can obtain a handle to a Windows DIB (Device Independent Bitmap) in memory. This can be passed to other applications or controls for processing. Each time the hDIB property is queried, a new copy of the image is generated and its handle returned. When the image is no longer required, the memory should be freed by calling the Windows GlobalFree function with the value returned from the property.


Assigning a DIB handle to the hDIB property will load the image into the control and automatically free the associated memory (eliminating the need to use Windows GlobalFree function). The image can then be processed like any other image. The hDIB property can be used with other imaging toolkits that can provide an image in DIB format. It is important that any value passed to the hDIB property is a valid handle to a global memory block containing a DIB. If not, the control may generate the dreaded General Protection Fault (GPF).


The hImage property is used when copying images between ImageMan controls. It cannot be passed to any other control type since it is only understood by the ImageMan image control. The hImage property is very similar to the hDIB property except that the image may be scaled when copying between controls using the hImage property. By specifying the size of the new image using the DstRight and DstBottom properties, the size of the internal image can be changed. The following code saves a 100x100 thumbnail of an image in the control named ImageControl1:


' Specify the size of the new image

ImageControl1.DstRight = 100 ' New Width

ImageControl1.DstBottom = 100 ' New height

ImageControl2.hImage = ImageControl1.hImage ' Create the thumbnail

ImageControl2.SaveAs "c:\thumb.tif" ' Save it

ImageControl2.Picture = "" ' Destroy the thumbnail


This code uses a second image control named, ImageControl2, to contain the thumbnail. This control can be invisible so the process of creating the thumbnail is invisible. If the DstRight and DstBottom properties had not been set then the image in the ImageControl2 control would be the same size as the image in the ImageControl1 control.


This same process can be used to scale the internal image maintained for an image control by specifying the new image size in the DstRight and DstBottom properties then assigning the hImage property to itself like this:


'Scale the image in the control to half size

ImageControl1.Dstright = ImageControl1.ImageWidth / 2

ImageControl1.DstBottom = ImageControl1.ImageHeight / 2

' Now assign the hImage to scale the image

ImageControl1.hImage = ImageControl1.hImage


As you can see the hImage property is very powerful. It is important that if you assign the hImage property to a variable that you assign that variable to an image control. If you don't, then the memory occupied by that image may not be freed.



© 2014 Data Techniques, Inc. All rights reserved.

Submit feedback on this topic