Download THBImage image and vector viewing and processing SDK
Download THBImage image and vector viewing and processing SDK

THBImage Viewer is a small and fast raster picture and vector data viewer.
THBImage Viewer is a small and fast raster picture and vector data viewer.

THBImage 4.8 F.A.Q
THBImage 4.8 F.A.Q

Can I use THBImage with MSAccess reports?

Yes. Simply place THBImage on the report. But there is some coding necessary to bind THBImage to the database field. The MSAccess demo project will show you how to achieve this.

How can I use the second control THBImageFrame in MSAccess?

THBImageFrame doesn’t work in MSAccess. It’s intended to display backgrounds but this feature is not available in MSAccess.

Can I create and use my own PopupMenu?

If you deactivate the default THBImage PopupMenu then you can implement your own one. All THBImage features are accessible through the provided properties and methods thus allowing you to create the same popup menu like the default one and add your own menu entries too.

I use MSAccess97 on Win95 and miss two PropertyPages, the Picture and the Color PropertyPage

If you use an old version of Win95 and you install MSAccess97 it is possible that there is no Msstkprp.dll available on your operating system. Simply copy it into the windows system directory and register it ‘regsvr32 Msstkprp.dll’. This should solve the problem and all Design-Time Stock Property Pages are available.

How to add THBImageEdit to your VB project?

Use Project->References in the Visual Basic IDE main menu. The displayed listbox shows you all COM objects that are available on your system. Select ‘THBImageEdit 1.0 Type Library’.

How to load an image?

Use the LoadPictureFromFile method to load the image from a file.

How to save an image?

Use the SavePictureToFile method to save the image to a file.

'Destination filename
strFileNew = "C:\YourPath\YourFile.bmp"
'Set format dependent properties
ie.BMPUseRLE = True
'And save as Windows BMP
ie.SavePictureToFile strFileNew, thbifBMP

How to load an image from memory?

Use the PicRawData properties to either assign byte array data or string data.

Dim ie As New THBImageEdit
Dim arData() As Byte

'Assign the byte data to THBImageEdit
ie.PicRawData = arData

How to save an image to memory?

Use the PicRawData

Dim ie As New THBImageEdit
Dim var as Variant

'Specify the output format
ie.PicRawDataImgFormat = thbifBMP
'Set format dependent properties
ie.BMPUseRLE = True
ie.PicRawDataGetCached = False  'We need BMP files, nothing else. Cached entries may be in a different format.
'Create a variant that contains the image data
var = ie.PicRawData

How to create thumbnails?

To create thumbnails simply load the original image, resize it to fit in a predefined space(here 320x200) without loosing the proportion and save it back to disk.

'Load the image
...

'Resize
ie.AlignImage 0, 0, 320, 200, ie.Width, ie.Height, _
        True, thbPosCC, thbStretchBoth, _
        lngLeft, lngTop, lngWidth, lngHeight
ie.Resize lngWidth, lngHeight, False

'Save the image
...

How to use THBImageEdit in conjunction with THBImage to view images?

Use THBImageEdit to load TIF, PNG,… pictures and assign it to THBImage using the Picture property.

Dim ie As New THBImageEdit
...
Set THBImage1.Picture = ie.Picture

This is the simplest way but very inefficient because you duplicate the image data. Imagine you load a 25MB image with THBImageEdit. Then you want to view it with THBImage. You use the Picture property to create a new OLE Picture object and assign it to the THBImage Picture property. The created Picture object takes 25MB too. And it is a time consuming step to create the new Picture object. Sure you can use this technique for small images but if you use larger images you should prefer the next technique.

A much faster way is to use the THBStdPicture property.

Dim pic As StdPicture
Set pic = ie.THBStdPicture

This property creates an OLEPicture compatible object without copying any image data thus it returns the new OLE Picture object without any noticeable time delay. The new OLE Picture object just references the image data from the THBImageEdit object. You can assign the new OLE Picture object to the THBImage control

Dim pic As StdPicture
Set pic = ie.THBStdPicture
Set THBImage.Picture = pic

'Shorter
Set THBImage.Picture = ie.THBStdPicture

The benefits are: faster and less memory consumption But there is a drawback too. The THBImage control measures the picture size when you assign a new picture to the Picture property. Whenever the picture object changes you must reassign it thus allowing THBImage to measure it again.

Dim pic As StdPicture
'Load a 10x10 image with THBImageEdit
ie.LoadPictureFromFile...
...
'Assign it to the THBImage control. The THBImage control measures the picture size.
Set THBImage.Picture = ie.THBStdPicture
...
'Rotate the original THBImageEdit object. 
'This indirectly changes the size of the THBStdPicture object assigned to the THBImage control.
ie.Rotate 45

'ATTENTION: If you do not reassign the picture the THBImage control will crash
'The THBImage control measures the picture size again and everything is fine.
Set THBImage.Picture = ie.THBStdPicture

When using THBImage in Databound mode THBImage needs to load TIF, PNG,… pictures from the database itself. Therefore assign a new initialized THBImageEdit object to THBImage. THBImage inherits all THBImageEdit features like loading TIF, PNG,…

Dim ie As New THBImageEdit
'Assign the THBImageEdit object to THBImage.
'This allows THBImage to access the image processing functions from THBImageEdit
Set THBImage1.THBImageEdit = ie

How to load an image directly from memory? (THBImage Standard Edition - VC++(MFC))

The code snippet below loads an image file from the harddisk to a byte array. Then it converts the byte array into the COleSafeArray. You can pass the COleSafeArray to the SetPicRawData method of the THBImage ActiveX control.

// ------------------------------
// Load the File from memory
void CDlgBrowser::LoadFileFromMemory(CString &strFile)
{
	long nSize = 0;
	char* pBuffer = NULL;
	
	//Load the image file into memory
	//The Standard Edition supports all file formats that you can 
	//load with the standard LoadPicture function. 
	//Bitmap(.BMP), Icons(.ICO), Cursor (.CUR), RLE-Files(RLE =
	//Run-length-encoded), WMF, EMF, GIF and JPG
	pBuffer = OpenFile(strFile, nSize);
	if(pBuffer == 0)
	{	MessageBox("Error loading File!", "THBImageDemo", MB_OK);
		return;
	}
	
	try
	{
		//Fill the Variant Array of Bytes
		COleSafeArray sa;
		LPBYTE pData = NULL;
		DWORD numElements = nSize;   //array size 
		sa.Create(VT_UI1, 1, &numElements);
		sa.AccessData((void**)&pData);
		memcpy(pData, pBuffer, nSize);
		sa.UnaccessData();
		 
		//Load and display it
		m_THBImage1.SetPicRawData(sa);
	}
	catch (_com_error &e)
	{	_bstr_t bstrDescription(e.Description());
		MessageBox((char*)bstrDescription, "THBImageDemo", MB_OK);
	}

	// Delete the buffer
	delete[] pBuffer;
}

// ------------------------------
// Load a file and return it in a buffer
char* CDialogBrowser::OpenFile(LPCTSTR szFileName, long& nSize)
{
	// Open the file
	FILE* pFile = fopen(szFileName, "rb");
	if(pFile == 0) // open failed ?
		return(0);

	// Compute the size of the file
	fseek(pFile, 0, SEEK_END);
	nSize = ftell(pFile);
	// Put the file pointer at the beginning
	fseek(pFile, 0, SEEK_SET);

	// Allocate a buffer big enough
	char* pBuffer = new char[nSize + 1];
	if(!pBuffer) 
	{	fclose(pFile); pFile = 0;
		return NULL;
	}
	// Put the file data in the buffer
	fread(pBuffer, nSize, 1, pFile);
	// Put a 0 char at the end
	pBuffer[nSize] = 0;
	// Close the file
	fclose(pFile); pFile = 0;

	// Return the buffer
	return(pBuffer);
}

How to load an image directly from memory? (THBImage Professional Edition - VC++(MFC))

The code snippet below loads an image file from the harddisk to a byte array. Then it converts the byte array into the COleSafeArray. You can pass the COleSafeArray to the PutPicRawData method of the THBImageEdit COM object.

// ------------------------------
// Load the File from memory
void CDlgBrowserPro::LoadFileFromMemory( CString &strFile)
{
	long nSize = 0;
	char* pBuffer = NULL;
	
	//Load the image file into memory
	pBuffer = OpenFile(strFile, nSize);
	if(pBuffer == 0)
	{	MessageBox("Error loading File!", "THBImageDemo", MB_OK);
		return;
	}
	
	try
	{
		//Fill the Variant Array of Bytes
		COleSafeArray sa;
		LPBYTE pData = NULL;
		DWORD numElements = nSize;   //array size 
		sa.Create(VT_UI1, 1, &numElements);
		sa.AccessData((void**)&pData);
		memcpy(pData, pBuffer, nSize);
		sa.UnaccessData();
		 
		//Load it with THBImageEdit
		m_ie->PutPicRawData((LPVARIANT)sa);

		//Update Pictureinfo
		UpdatePicInfo();

		//Assign the loaded image to the Image Viewer
		//control THBImage1. This does NOT duplicate
		//the image data. We just assign a reference to
		//the THBImageEdit object.
		m_THBImage1.SetRefPicture( m_ie->GetTHBStdPicture());

	}
	catch (_com_error &e)
	{	_bstr_t bstrDescription(e.Description());
		MessageBox((char*)bstrDescription, "THBImageDemo", MB_OK);
	}

	// Delete the buffer
	delete[] pBuffer;
}

How to load an image directly from memory allocated with GlobalAlloc? (THBImage Professional Edition - VC++(MFC))

The code snippet below loads an image directly from memory allocated with GlobalAlloc. It converts the byte array into the COleSafeArray. You can pass the COleSafeArray to the PutPicRawData method of the THBImageEdit COM object.

//------------------------------
//Load the picture from HGLOBAL
BOOL CDlgPro::LoadPictureFromHGLOBAL( HGLOBAL hGlobal, int nSize)
{
	LPBYTE pBuffer = NULL;
	BOOL bRet = FALSE;

	if(!hGlobal) return FALSE;

	pBuffer = (LPBYTE)GlobalLock(hGlobal);
	if(pBuffer == 0)
	{	MessageBox("Error loading File!", "THBImageDemo", MB_OK);
		return bRet;
	}
	try
	{
		//Fill the Variant Array of Bytes
		COleSafeArray sa;
		LPBYTE pData = NULL;
		DWORD numElements = nSize;   //array size 
		sa.Create(VT_UI1, 1, &numElements);
		sa.AccessData((void**)&pData);
		memcpy(pData, pBuffer, nSize);
		sa.UnaccessData();
		
		//Load it with THBImageEdit
		m_ie->PutPicRawData((LPVARIANT)sa);

		//Update Pictureinfo
		UpdatePicInfo();

		//Assign the loaded image to the Image Viewer
		//control THBImage1. This does NOT duplicate
		//the image data. We just assign a reference to
		//the THBImageEdit object.
		m_THBImage1.SetRefPicture( m_ie->GetTHBStdPicture());

		bRet = TRUE;
	}
	catch(_com_error &e)
	{	_bstr_t bstrDescription("Error loading File!");
		MessageBox((char*)bstrDescription, "THBImageDemo", MB_OK);
	}

	GlobalUnlock(hGlobal);
	return bRet;
}

How can I change the resolution to 204 x 196 dpi?

The following description assumes that ‘ie’ is a new THBImageEdit object. Imagine you load an image with the dimension 1000x1000 pixels and 2000x2000dpi. 2000x2000dpi means that there are 2000 pixels per inch this means that the image has a size of 0.5x0.5 inch. ie.LoadPictureFromFile “c:\YourPic.jpg”

Now you can set the dpi values to the values you need.

ie.DPI_X = 204
ie.DPI_Y = 196

This does not affect the image data in any way. You still have 1000x1000 pixels. But at 204x196dpi. Now you can test this

lngWidth = ie.Width
lngHeight = ie.Height

You get 1000x1000 pixels. Now we would like to know the size measured in inch

ie.CnvPixelToTwipsImg lngWidth, lngHeight

CnvPixelToTwipsImg returns twips and takes the dpi values assigned to the THBImageEdit object into account. To convert twips to inch simply divide through 1440

dblInchX = CDbl(lngWidth) / 1440
dblInchY = CDbl(lngHeight) / 1440

We get 4.9x5.10 inch. So simply assigning different dpi values does not affect the pixel size or image data but changes the logical size. The logical size is the size of the image on the paper o screen. We started with a size of 0.5x0.5 inch but the new one has a size of 4.9x5.10 inch. If we would print the image on the paper it would be much larger than the original one.

To adjust the logical size back to 0.5x0.5 inch we need to resize the image to a different pixel size. This means that we loose image data because we go down to a lower resolution(from 2000x2000 to 204x196).

NewPixelX = NewDpiX * OriginalSizeInchX
102pixel = 204 * 0.5inch
NewPixelY = NewDpiY * OriginalSizeInchY
98pixel = 196 * 0.5inch

Execute the resize operation

ie.Resize 102, 98, True

When you now query the size of the image again, you’ll get 102x98pixels, 204x196dpi And a logical size of 0.5x0.5 inch The new image has the same size as the original and that is what we actually want.

How can create multipage tiff files?

You can use the method lngFramesCount = ie.FrameCount(“C:\yourpath\yourfile.tif”) to retrieve the number of frames contained in the tif.

You can use the property FrameIndex ie.FrameIndex = lngFramesIndex to set the frame you’d like to load lngFramesIndex ranges from 0 to lngFramesCount -1

ie.LoadPictureFromFile "C:\yourpath\yourfile.tif"

Loads the frame you specified with FrameIndex.

The vbdemo1 frmProfessional demo contains these methods too.

Example: Dim ie As New THBImageEdit strFile =”Yopurpic.tif” nCount = ie.FrameCount(strFile) ie.FrameIndex = 0 ie.LoadPictureFromFile strFile ie.FrameIndex = 1 ie.LoadPictureFromFile strFile … ie.FrameIndex = nCount -1 ie.LoadPictureFromFile strFile

Example2:

'------------------------------
' Save some pictures into one multipage tiff
Private Sub butOk_Click()
	Dim ie1 As New THBImageEdit
	Dim ie2 As New THBImageEdit
	Dim ie3 As New THBImageEdit
	Dim ie4 As New THBImageEdit
	Dim ie5 As New THBImageEdit
	Dim strFile1 As String
	Dim strFile2 As String
	Dim strFile3 As String
	Dim strFile4 As String
	Dim strFile5 As String
	Dim strFileDst As String
	Dim Images() As THBImageEdit
	
	On Error GoTo ErrHandler
	
	strFile1 = "I:\18.jpg"
	strFile2 = "I:\22.jpg"
	strFile3 = "I:\35.jpg"
	strFile4 = "I:\41.jpg"
	strFile5 = "I:\27.gif"
	strFileDst = "I:\Multipage.tif"
	
	If Not modGlobals.LoadFile(strFile1, ie1) Then Exit Sub
	If Not modGlobals.LoadFile(strFile2, ie2) Then Exit Sub
	If Not modGlobals.LoadFile(strFile3, ie3) Then Exit Sub
	If Not modGlobals.LoadFile(strFile4, ie4) Then Exit Sub
	If Not modGlobals.LoadFile(strFile5, ie5) Then Exit Sub
	ReDim Images(0 To 4)
	Set Images(0) = ie1
	Set Images(1) = ie2
	Set Images(2) = ie3
	Set Images(3) = ie4
	Set Images(4) = ie5
	
	ie1.SavePictureMultiToFile Images, strFileDst, thbifTIF
	MsgBox "Multipage picture saved!"
	Exit Sub
	
ErrHandler:
	MsgBox Err.Description
End Sub

Is there a way to make the built in popup menu pop up without pressing the right mouse button? Can I create my own popup menu for the THBImage ActiveX control?

Please download this popup menu example for THBImage. It creates a new popup menu that you can design as you want. imgpopup.zip

Do you have an example of dragging an image from windows explorer and dropping it onto the THBImage ActiveX control?

Set the property DropFiles = True in the Form_Load event and implement the DropFile event.

Private Sub Form_Load()
	...
	THBImage1.DropFiles = True 'Enable Ole Drag&Drop
End Sub

'------------------------------
' User dropped a file on the image control
Private Sub THBImage1_DropFile(ByVal strFilename As String)
	Dim pic As IPictureDisp
	' Load the file and update the display
	If strFilename &lt&gt "" Then
		Set pic = LoadPicture(strFilename)
		Set THBImage1.Picture = pic
	End If
End Sub

I am trying to overlay an image onto blue background. I have a mask that goes from black to white in the shape of an oval.

Below is the solution to the problem. You can download the mask picture here. imgmask.zip

'------------------------------
' Overlay with gradual ellipse transition
Private Sub butOverlayEllipse_Click()
	Dim strFile1 As String
	Dim strFile2 As String
	Dim strFileDst As String
	Dim ieDst As New THBImageEdit
	Dim ieImg As New THBImageEdit
	Dim ieMask As New THBImageEdit
	Dim nWidthDst As Long
	Dim nHeightDst As Long
	
	On Error GoTo ErrHandler
	
	strFile1 = "I:\Picture\monkbig.bmp"
	strFile2 = "I:\Picture\maskellipse.bmp"
	strFileDst = "I:\Picture\result.jpg"
	'Load the image
	If Not modGlobals.LoadFile(strFile1, ieImg) Then Exit Sub
	'Load the 8bit grayscale mask
	If Not modGlobals.LoadFile(strFile2, ieMask) Then Exit Sub
	
	nWidthDst = ieImg.Width
	nHeightDst = ieImg.Height
	'Mask should have the same size as the image
	ieMask.Resize nWidthDst, nHeightDst, False
	
	ieImg.ConvertToBPP thbbpp24Bit, thbDitherFS, True
		
	'Create blue background
	ieDst.Create 1, 1, thbbpp24Bit
	ieDst.SetPixelRGB 0, 0, rgb(0, 0, 255)
	ieDst.Resize nWidthDst, nHeightDst, False
	'Overlay image with grayscalemask
	ieDst.OverlayWith8BitMask ieImg, ieMask, 0, 0
	
	'Save result
	ieDst.JPGGrayscale = False
	ieDst.JPGProgressive = False
	ieDst.JPGQuality = 60
	ieDst.SavePictureToFile strFileDst, thbifJPG
	
	ieDst.Copy ie
	'Draw the result
	butDraw_Click
	Exit Sub
	
ErrHandler:
	MsgBox Err.Description
End Sub

I’d like to let the user draw a rectangle on the image and then crop the selected rectangle out of the image.

Please download the short VB demo. imgpullquote.zip

I’d like to display thumbnails(thumbs) of a directory on the hard disk.

Please download the short VB demo. This is a very simple approach to display thumbs there are many ways to optimize and improve the thumb creation process. Just to listen some possibilities to improve the thumbviewer: At first create thumbs of small images Update the thumbviewer after each loaded thumb Use multithreading Cache the thumbs on the hard disk and just recreate them if necessary imgthumbs.zip

I see that the CTHBImageFrame is in the activeX controls list, but I am not sure how to use it in VC++

THBImageFrame is quite useful in VB. But you can’t use it in VC++. Simply ignore it.

How can I add THBImage Control to my MFC app?

At first import the THBImage 4.8 ActiveX control. Project->Add to Project->Components and controls VC++ will create wrapper classes CTHBImage(thbimage.h) and CTHBRegion(thbregion.h)

Then copy the files THBImg40.h THBImg40.cpp THBImE20.h THBImE20.cpp that are part of the VcDemo project into your project folder and add the header files to your project. But just the header files. These files are necessary to get the convenient enumeration types(constants) and to create the COM object.

How can I clear the THBImage Control in my MFC app? I haven’t found a Clear method.

Simply assign a NULL picture.

m_THBImage1.SetRefPicture(NULL);

Can i use THBImage to create background for my MDI form?

Yes, please download the short VB demo. imgmdibackground.zip

I need to print a picture on a printer that prints 6x8 inches.

I need to print a picture on a printer but the program has to have the ability to stretch the picture (or shink) to fit the printer and keep aspect ratio.

There are some really easy to use Printing methods where you can use any units(inch, metric, pixel, twips,..) and you can keep the proportion of the original picture.

'Print a picture in its original size to the upper left corner
ie.PrintPic Printer.hdc, thbguPixel, 0, 0

'Print the picture best fitted into the 6x8 inch area
ie.PrintPicAligned Printer.hdc, thbguThousandthsOfAnInch, 0, 0, 6000, 8000, True, thbPosCC, thbStretchBoth

I want to print 4 images on a 8.5 X 11 page.

Please download the short VB demo. imgprintquarter.zip

I need to clear a picture from the THBImage ActiveX Control?

Set THBImage1.Picture = Nothing

When I take your example (frmOverlay) of an overlay, change the included pictures to my own JPG’s it does not overlay!

All pictures should have the same size, thats not a requirement but if you use the standard 320x200 picture and overlay it on a 2000x2000 photo then the overlay will just happen in the upper left corner. Use the resize method to match the size.

The overlay animation runs through a loop that may require 1minute with large pictures. Set breakpoints in the source code to mark the start and end of the animation process(a ‘for’ loop running from 0 to 100)

The overlay is not fileformat dependent, it doesn’t matter if you use jpg,bmp, png,tga,.. But it’s important that you use 24bit(rgb) pictures or convert it to rgb:

ie.ConvertToBPP thbbpp24Bit, thbDitherFS, True

I bought THBImage Professional but still get a nag screen? How can I get rid of them.

When you place a THBImage ActiveX control on a form you will get a nag screen displaying something like “THBImage ActiveX control is not licensed…” To get it away follow thse steps:

Applying the serialnumber to the THBImage ActiveX Control:

Start your development environment and open any project containing a THBImage ActiveX control. Open the form that contains the control. Display the property pages of the control and select the property sheet with the registration information. In Visual Basic you display the property pages by right clicking on the control and selecting ‘Properties…’ in the Popup menu. At the bottom of the registration property sheet you can paste the serialnumber(without quotation marks) into the text field and click on the ‘Apply Serialnumber’ button below the text field.

When you open up the form containing the THBImage control the next time the nag screen will not appear any more. You can find further details about serialnumbers at ControlLic

When you create a THBImageEdit Com object you will get a nag screen displaying something like “THBImageEdit Com object is not licensed…” To get it away follow thse steps:

Assigning the serialnumber to the THBImageEdit COM object:

When you create a new instance of the THBImageEdit object use the property RegistrationKey to assign the serialnumber. Example: Dim ie As New THBImageEdit ie.RegistrationKey = “User1|IMG45012345:User1|IMGEDIT45012345”

After successfully assigning the serialnumber to THBImageEdit the nag screen will not appear any more and THBImageEdit will work without any limitations.

You can find further details about serialnumbers at ComLic

There is a nag screen for the Region add on too, displaying something like “The Region AddOn requires an additional license…” You will just get this message if you are using methods or properties from the THBImage control that require the Region AddOn(concerns all methods starting with Region, RegionAdd, RegionStartPoint, RegionStartPolygon,..) To get it away follow thse steps:

Applying the Region AddOn Serialnumber to the THBImage ActiveX Control:

You can concatenate Serialnumbers by separating them with ’:’ To license your THBImage control and the Region AddOn you need to concatenate both serialnumbers: Example: THBImage Control: User1|IMG450123455678 Region AddOn: User1|IMGRG4501A23CE4D5 This is the resulting Serialnumber that you must apply: User1|IMG450123455678:User1|IMGRG4501A23CE4D5

Start your development environment and open any project containing a THBImage ActiveX control. Open the form that contains the control. Display the property pages of the control and select the property sheet with the registration information. In Visual Basic you display the property pages by right clicking on the control and selecting ‘Properties…’ in the Popup menu. At the bottom of the registration property sheet you can paste the serialnumber(without quotation marks) into the text field and click on the ‘Apply Serialnumber’ button below the text field.

After successfully assigning the serialnumber to THBImage the region nag screen will not appear any more. You can find further details about serialnumbers at ControlLic

The property page of the control displays all Activated modules. It must contain ‘THBImage control’ and ‘Region AddOn’

Or you have a THBResize control on the form. When you place it on a form you will get a nag screen displaying something like “THBResize ActiveX control is not licensed…” The THBResize control is a different control requiring its own license, it is not part of THBImage. If you don’t want to use it, simply remove it from the form.

How can I use THBImage with CrystalReports?

For this example you need a VB project containing a crystal reports designer. Add a DB Connection to a database table that contains at least two fields. The Id (pimary key) plus a text field that contains a filename to the image file.

Simply implement the Format event. There you have access to the DB Fields and you can use the THBImageEdit object to load the picture file and to calculate the proper display size.

You can not place a THBImage control on the CrystalReports designer because Crystal Reports just allows some specific cntrols.

In the example below we use CrystalReports picture control to display the picture.

Normally it is possible to load the image data directly from a DBField, but this didn’t work in our constellation (CrystalRepprts 7, MsAccess 97). Other DBMS or later versions of CrystalReports may behave differently and this line may work: ie.PicRawData = FieldImage.Field.Value

Private Sub Section3_Format(ByVal pFormattingInfo As Object)
	Dim ie As New THBImageEdit
	Dim strFile As String
	
	On Error GoTo ErrHandler
	
	'Currently it is not possible to directly load the
	'image data from the blob value because there
	'is no way to get something out of it.
	'This may behave different with other DB drivers
	'ie.PicRawData = FieldImage.Field.Value
		
	'Build the image filename
	strFile = "H:\Pictures\" & FieldFilename.Field.Value
	'Does it exist
	If Dir(strFile) = "" Then
		MsgBox "File '" + strFile + "' doesn't exist!"
	Else
		'Load the file
		ie.LoadPictureFromFile strFile
				
		'Keep the aspect ratio
		If (ie.Width > 0) And (ie.Height > 0) Then
			Dim lngLeft As Long, lngTop As Long
			Dim lngWidth  As Long, lngHeight As Long
			ie.AlignImage Pic1.Left, Pic1.Top, _
				Pic1.Width, Pic1.Height, _
				ie.Width, ie.Height, _
				True, thbPosCC, thbStretchBoth, _
				lngLeft, lngTop, lngWidth, lngHeight
			Pic1.Left = lngLeft
			Pic1.Top = lngTop
			Pic1.Width = lngWidth
			Pic1.Height = lngHeight
			Set Pic1.FormattedPicture = ie.THBStdPicture
		End If
	End If
	Exit Sub
	
ErrHandler:
	MsgBox Err.Description
End Sub

How can I use THBImage with DataDynamics ActiveReports?

For this example you need a VB project containing an active reports designer. Add a ActiveReports ADO DataControl to the reportand open a connection to a database table that contains at least two fields. The Id (pimary key) plus a text field that contains a filename to the image file. Or a blob field containing the image data.

Simply implement the Format event. There you have access to the DB Fields and you can use the THBImageEdit object to load the picture from file or directly frm the blob field.

You can place a THBImage control on the ActiveReports designer to show the picture.

Private Sub Detail_Format()
	Dim ie As New THBImageEdit
	Dim strFile As String
	Dim bLoadFromDBField As Boolean
	
	On Error GoTo ErrHandler
	
	bLoadFromDBField = True
	
	If bLoadFromDBField Then
		'Load the image data directly from the blob field
		ie.PicRawData = DataControl1.Recordset.Fields("Image").Value
	Else
		'Build the image filename
		strFile = "H:\Pictures\" & Field3.Text
		'Does it exist
		If Dir(strFile) = "" Then
			MsgBox "File '" + strFile + "' doesn't exist!"
		Else
			'Load the file
			ie.LoadPictureFromFile strFile
		End If
	End If
	
	'Show it
	If (ie.Width > 0) And (ie.Height > 0) Then
		THBImage1.BackColor = RGB(255, 0, 0)
		THBImage1.BackColorOn = True
		THBImage1.PositionPic = thbPosCC
		THBImage1.StretchPic = thbStretchBoth
		THBImage1.KeepAspect = True
		Set THBImage1.Picture = ie.THBStdPicture
	End If
	Exit Sub
	
ErrHandler:
	MsgBox Err.Description
End Sub

THBImage control placed on a DataDynamics ActiveReports designer displays a nag screen on the users machine but not on the development machine?

Normally you assign the serial by using the property page of the THBImage control but this doesn’t work with ActiveReports.

To overcome this you need to do two things:

Request the nonag version of THBImage from us. (Simply send us an email). Customers that bought THBImage will get it.

Use the Initialize event to assign the serial to the THBImage control: Private Sub ActiveReport_Initialize() THBImage1.RegistrationKey = “User1|IMG45012345:User1|IMGEDIT45012345” ..End Sub

If a VB form is in design time THBImage reads the serial from the registry HKEYLOCALMACHINE \ SOFTWARE \ THBComponentware \ THBImage at the development machine. When you compile the exe THBImage writes the serial into the exe. At run time THBImage reads the serial from the exe.

This works fine but in the ActiveReports case there is no distinction between design and runtime. THBImage always reads the serial from the registry. This works on your machine because on the development machine the registry key exists but doesn’t work on a users machine. This is the reason why this happens.

How can I draw lines or text on the image?

If you’d like to draw on the image without affecting the underlying image data (like drawing on an additional layer) then refer to the RegionAddOn.

If you’d like to modify the image data. Either for placing a textlabel on the image or for creating a thumbnail with a frame around it then refer to the THBDeviceContext COM object. After modifying the image data you can save the new image back to disk.

Is it possible to generate 8 Bit Grayscale JPEG?

Yes, set the JPGGrayscale option to True and ensure that your imagedata is already grayscale.

The THBImageEdit object dose not use the JPEG2000 algorithm although I am using ie2.JPEG2000Settings

The imageformat parameter ie.PicRawDataImgFormat = ImageFormat defines which fileformat you export. It is not important which settings you set. In fact you can set all fileformat specific settings (jpg jpg2000 png bmp ,…) at once, the property PicRawDataImgFormat still defines what you export.

THBAdvancedImageProc.Resize with Supersampling interpolation does not work!

Supersampling interpolation, can not be applied for image enlarging. We changed this, when you now use Supersampling interpolation for enlarging it will automatically choose another interpolation mode instead of throwing the error message.

Converting the Access mdb to my access version

When you open the THBImage.mdb access will convert it to your Access version. It is important that before doing this ensure that the access mdb has valid references to ‘THBImage 4.8 Library’ ‘THBImageEdit 4.8 Library’ If the path is invalid you may get troubles converting the access mdb to the new version. Before converting the mdb go to the code view and select Extras->References in the Access or VBA menu depending on your access version. Look at the exact path of the THBImg45.dll and THBIme45.dll validate that these paths exist on your harddisk.

Can I open the whole PSD like in Photoshop and then say turn off layer 12, layer 20 etc.?

THBImageEdit loads a PSD file. Layers are treated like pages of the PSD file. This allows you to load each layer of the PSD file using the FrameCount, FrameIndex properties. You can even access one mask per layer.

But to dislay all separate layer as a single image you now you have to implement all the blending effects that photoshop supports.

Take layer 10. Use the THBImageEdit ImageProperties property to get the blending mode and position coordinates. Draw it according to the blending mode and position.

Take layer 9. Use the THBImageEdit ImageProperties property to get the blending mode and position coordinates. Draw it according to the blending mode and position.

Take layer 8. Use the THBImageEdit ImageProperties property to get the blending mode and position coordinates. Draw it according to the blending mode and position.

If you implement this you will have something that looks very close to that what you get in Photoshop.

But there are still some obstacles. Photoshop supports up to two masks per layer. Masks can have other dimensions and positions than the layer itself.

THBImage will NOT load the second mask.

You have to apply the layer mask correctly to get the right effect.

So just loading the imagedata is by far not enough to get a Photoshop application.

How do I apply color values in .NET?

The .NET framework offers a Color class that can be used to create colors in .NET. THBImage often requires colors as an integer value, to convert from Color to int use the .ToArgb() function. .net adds an alpha value of 255 by default this makes it invalid for the use with thbimageedit. Therefore it is necessary to remove the alpha part by filtering away the alpha part using a logical AND operation. int col = (int) Color.FromArgb(255, 255, 255).ToArgb() & 0x00ffffff;

To create a white color use this code Color.FromArgb(255, 255, 255) before applying it to the THBImageEdit class convert it in this way (int) Color.FromArgb(255, 255, 255).ToArgb() & 0x00ffffff;

In case of 8bit palette pictures or 8bit grayscale pictures you can use a value ranging from 0 to 255 instead. This represents the shade of gray or an index to the color palette.

How do I rotate an image in .NET?

You can take a look at the frmProfessional there is a Rotate function. But in general, load the image, call Rotate and display it. When doing multiple rotations, load it once and then copy the original and rotate it. Enterprise Edition customers should use the THBImageEdit.AdvancedImgProc.Rotate function.

THBImageEdit ieRotrate;
THBImageEdit ieOriginal = new THBImageEdit();
ieOriginal.LoadPictureFromFile(...);

for (int i=0; i

How to use THBImage control via code in .NET?

Create the THBImage control via code and add it to the controls collection, it will show up a big black “X”. To prevent this please search in your forms for the SysKey property. It’s a very long encrypted text. After creating the THBImage control via code assign the SysKey property to get rid of the black X.

Your documentation talks about a THBStdPicture property all over the place, but for the life of me I cannot find this object in your assembly.

This is the way it has to be done in ActiveX/Com: Set THBImage.Picture = ie.THBStdPicture But in .Net use the THBImageEdit property to assign a THBImageEdit object for viewing: thbImage1.THBImageEdit = ie; Or assign a .net image directly thbImg.Picture = Image.FromFile(@”C:\YourPath\YourPic.jpg”);

How can I assign a Cursor to THBImage.Net control?

In THBImage each Command has its own cursor. So when starting the Pan command you get the pan Hand cursor, when starting the zoom window command you get the zoom window cursor. The default command is the Select command which handles the selection of region objects. When assigning a cursor use the MousePointer property. When you start the selection command the next time it will use the MousePointer as a Cursor. So just assigning your cursor to the MousePointer property is not sufficient. You have to rfestart the xcommand too to apply the new cursor. In your code this looks like this:

thbImg1.MousePointer = Cursors.No;
thbImg1.StartDefaultCommand();