
How can I create Esri SHP files?
To write vector data like Shape files you need the THBVector object.
You can fill it with data either by loading existing vector files or by manually populating it with data.
Use the THBVector.SaveToFile method to write out the data. Shape files can consist of multiple files. The SHP file contains the geometry. The dbf file contains additional attributes for each geometry object and a SHX index file.
You can use the FileFormatSettings properties to affect which files are generated.
Vec.FileFormatSettings.SHPWriteDBase = TRUE;
Vec.FileFormatSettings.SHPWriteIndexFile = TRUE;
Vec.FileFormatSettings.SHPWriteLayer = "0";
How can I convert Esri SHP to DXF and DGN to DXF?
Use the THBVector object to load your shp file. Vec.LoadFromFile “c:\YourShape.shp”, thbvfSHP After loading you will have one layer in the THBVector object that contains the geometry.
If you set Vec.LoadFolder = TRUE; then all shp files of a folder will be loaded. Each file comes into a separate layer. You can access the layers through the THBVector object Vec.Layers
To write out dxf data call Vec.SaveToFile "C:\new.dxf", thbvfDXF All layers will be added to the dxf file.
Why are there small triangles across my vectordata?
The evaluation version of THBVector adds triangles to the data.
How can I remove the Zoom Buttons from THBView?
Use the THBView.UserInterface object to access and modify the buttons that THBView offers by default. You can remove existung buttons or add new ones.
THBView1.Scroll.Enabled = True
THBView1.UserInterface.Clear
THBView1.UserInterface.PageNavigation = False
THBView1.UserInterface.AddButton thbvbDrawCircle, thbcaBottom
THBView1.UserInterface.Recreate
How can I view pictures from the web?
The easiest way is to use THBImageEdit.LoadPictureFrom Url method. Or use the THBWebRequest object to get full control over all aspects of http and ftp access.
'Loading from http or ftp url using the webrequest object
'web.URL = "http://www.your.com/94425.jpg"
web.URL = "ftp://www.your.com/00094425.jpg"
web.Start
ie.LoadPictureFromMem2 web.DownloadedData, thbifAutoDetect
' Simplest way
'ie.LoadPictureFromUrl web, "http://www.your.com/94425.jpg", thbifAutoDetect, 0
ie.LoadPictureFromUrl web, "ftp://www.your.com/00094425.jpg", thbifAutoDetect, 0
How can I use secure ftp?
For password protected ftp use the Web.UserPwd property
UserPwd User and password [user name]:[password] to use for the connection. Use HttpAuthentication to decide authentication method.
When using NTLM, you can set domain by prepending it to the user name and separating the domain and name with a forward (/) or backward slash (). Like this: ‘domain/user:password’ or ‘domainuser:password’. Some HTTP servers (on Windows) support this style even for Basic authentication.
When using HTTP and FollowLocation, THBWebRequest might perform several requests to possibly different hosts. THBWebRequest will only send this user and password information to hosts using the initial host name (unless UnrestrictedAuthentication is set), so if THBWebRequest follows locations to other hosts it will not send the user and password to those. This is enforced to prevent accidental information leakage.
After loading the image and zooming in and out a few times vb crashes.
Vb displays an error message like this: Faulting application vb6.exe, version 6.0.81.76, faulting module thbvie50.dll, version 5.0.2.1, fault address 0x000838e2.
Please ensure that you prevent dll unloading. Vb simply unloads dlls athough they are still in use, which causes ugly exceptions. This is the most obvious cause of a crash.
' We have to keep the dlls alife therefore create objects
' that ensure that our dlls don't get unloaded
Public iestd As THBImageStandard
Public ie As THBImageEdit
Public view As THBViewLayer
Public vec As THBGeometry
Private Sub Form_Load()
On Error GoTo ErrHandler
Set iestd = New THBImageStandard
Set ie = New THBImageEdit
Set view = New THBViewLayer
Set vec = New THBGeometry
Exit Sub
ErrHandler:
MsgBox Err.Description
End Sub
I’m using THBTwain 5.0 to control the twain scanner from Fujitsu fi-5120c. When I run a small test program with .Net C# on VS2005 to acquire the image from scanner everything is ok but when I exit the program and restart again then I get the error message like “Please check you scanner is connect the cable and power supply”. At this state other applications on PC can’t access the scanner it says “Other programs are using this scanner”. So I have to restart my PC again then it come to work again.
To solve this you can explicitly try to use the Close function and eventually EndSession function at end of scan function.
private void button1_Click(object sender, EventArgs e)
{
THBImageTwain imgtwain = new THBImageTwain();
THBTwain twain = imgtwain.InterfaceITHBTwain;
twain.Init();
twain.AppInfoSet(...);
twain.SelectByType(false);
twain.Open();
try
{
twain.MsgNotify = true;
twain.TwainModeModal = true;
twain.AcquireFiles("e:\\Scanned.bmp",
thbDTWAIN_Filetransfer.thbDTWAIN_FF_BMP ,
thbDTWAIN_FileAcquireFlags . thbDTWAIN_FAF_USENAME ,
thbDTWAIN_PixelType.thbDTWAIN_PT_BW, 2, false, true);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
twain.Close();
twain.EndSession();
imgtwain.Dispose();
imgtwain = null;
twain = null;
}
}
How can I scan tiff documents?
There are two ways to do this, either in modal mode where you scan all pages and then save the result using SaveAllAcquiredImages. Or in modeless mode (see frmTwainModeless) where you can process each page immediately after scanning. This is quite useful for larger scan jobs scanning 100 pages or so you can process each page immediately after scanning. You will get the AcquirePageDone event where you should append the scanned document to the existing multipage tiff file.
Private Sub twainevents_AcquirePageDone(plngReturn As Long)
On Error GoTo ErrHandler
'Create an array large enough to store all pages
Dim uf As New THBUtilsFactory
Set arImages = uf.CreateTHBArrayObject
arImages.Size = 1
'Fill the array with the acquired page
Dim ie As THBImageEdit
Set ie = imgtwain.CurrentAcquiredImage
'Set PDF/TIFF export options
If ie.BitsPerPixel = 1 Then
'Export TIFF with CCITT Group4 Compression
ie.FileFormatSettings.TIFFCompression = thbTIFFCompCCITTFAX4
ie.FileFormatSettings.TIFFFaxMode = thbTIFFFaxModeClassF
ie.FileFormatSettings.TIFFGroup4Options = thbTIFFGroup4None
Else
ie.FileFormatSettings.TIFFCompression = thbTIFFCompPACKBITS
End If
'Put it into the array
arImages.At(0) = ie.InterfaceITHBObject
'Save the multipage file
bAppend = FileExists(strFileDst)
Set ieSave = New THBImageEdit
If bPDF Then
ieSave.FileFormatSettings.PDFSettings "THBImage", _
Format(Now), _
"THBComponentware", "THBImage", _
strFileDst, strFileDst, "PDF, Picture"
ieSave.SavePictureMultiToFile arImages, strFileDst, thbifPDF, bAppend
Else
ieSave.SavePictureMultiToFile arImages, strFileDst, thbifTIF, bAppend
End If
Exit Sub
ErrHandler:
MsgBox Err.Description
End Sub
After drawing rectangle in the THBView, how to move the selected rectangle?
You can use the commands thbCmdMoveGeometry, thbCmdEditGeometry thbCmdRotateGeometry. To start a command use THBView.Commands.Start(thbCmdMoveGeometry) Now the user can move the selected geometry.
If you’d like to do this in your code you may go this way. Let the user select one geometry object. Now use THBView.SelectedLayer.All.GetAt(0).Translate(10, 10); To move the geometry 10 world units to the right and top. Sure you could do this in one line but you should secure some things
THBGeometryList gl = thbView1.SelectedLayer.All;
if(gl.Count != 1) return;
gl.GetAt(0).Translate(10, 10);
This was quite easy. The more complicated part is to enforce a THBView redraw. THBView will just redraw anything if you set the layer to dirty within BeginUpdate and EndUpdate. So here is the complete code
// get the first selected geometry
THBGeometryList gl = thbView1.SelectedLayer.All;
if(gl.Count != 1) return;
vec_.BeginUpdate();
// move the geometry
gl.GetAt(0).Translate(10, 10);
// set the layer dirty
vec_.GetLayers().GetAtIndex(0).IsDirty = true;
vec_.EndUpdate();
// clear the selection
thbView1.SelectedLayer.RemoveAll();
thbView1.Redraw();
How can I set a picture on the Geometry?
The standard geometry objects can not display pictures or show tooltips, instead you need a THBRegionGeometry. It extends the capabilities of the basice point, line, polygon,… geometries.
To assign pictures to the THBRegion geometry you have two choices. You can either use an imagelist (read about imagelists in the docu) THBUtilsFactory uf = new THBUtilsFactory(); THBImageList imageList = uf.CreateTHBImageList(); imageList.Load… Now assign the pictures from the imagelist to the region object.
The second way is to create new pictures and assign them
THBUtilsFactory uf = new THBUtilsFactory();
THBImageStandard imagePin = uf.CreateTHBImageStandard();
THBImageStandard imagePinHigh = uf.CreateTHBImageStandard();
imagePin.LoadPictureFromFile(Utils.GetPictureDir() + "18.jpg", thbImgFormat.thbifAutoDetect);
imagePinHigh.LoadPictureFromFile(Utils.GetPictureDir() + "22.jpg", thbImgFormat.thbifAutoDetect);
geomregion.Picture = imagePin;
geomregion.PictureHighlighted = imagePinHigh;
I don’t know if I should use THB.THBImageLib.dll or THB.THBImageLib2005.dll version of the .Net dlls?
The THBImage.chm that comes along with the thbimg.zip THBImage5.0 setup contains a Deployment section that describes the files in detail. .Net assembly dlls are built against a .Net framework. There are 1.0 1.1 2.0 3.0 3.5 .Net frameworks available till now. THB.THBImageLib.dll was built against 1.1 THB.THBImageLib2005.dll was built against 2.0 2005 means Visual Studio 2005 here which comes with .Net2.0 by default. Now there is Visual Studio 2008 available too, maybe we add THB.THBImageLib2008.dll too. So depending on your preferred .Net Framework you an choose the assembly.
Is there a way to call the THBTwain.Select method so that it does not display a pop-up box?
You can use THBTwain.EnumSources which returns all available scanners. Then create your own listbox where you offer all twain devices to the user. Store the selected twain device in your applications settings and the next time you can choose the twain scanner by using THBTwain.SelectByName.
TVieAP50.dll not found
If you have troubles like TVieAP50.dll not found then there are three common problems:
- a 32bit executeable tries to find 32bit dlls but just finds 64bit dlls
- a 64bit executeable tries to find 64bit dlls but just finds 32bit dlls
- MSVCRT90 runtime files folder is missing or MSVCRT90 setup was not installed(which is just necessary if there is no MSVCRT90 runtime files folder)
- While using VisualStudio.NET you may get this message because VisualStudio.NET copies the THB.THBImage.dll .Net assembly from the bin32/All folder (or bin64/All respectively) into the projects output folder. As a consequence the native dlls like TVieAP50.dll are no longer in the same folder along with the .Net assembly THB.THBImage.dll.
To solve this please
- Remove the binary folder that you don’t need (bin32/All or bin64/All).
- The easiest way is to create a PATH environment variable pointing to the binary folder but this is an optional step.
- Run the proper vcredist executeable. There are separate versions for 32bit and 64bit.
- Set the CopyLocal property of the THB.THBImage.dll reference to False.
Native dlls like TVieAP50.dll have to be in the same folder along with the .Net assembly THB.THBImage.dll
Each vcredist has a version number. Downloading any package from www.microsoft.com does not guarantee that you have the proper version. So you have to take the version that we deliver along with the THBImage SDK setup or take care that you download the proper version at www.microsoft.com.
How to deploy 32bit version
To deploy the 32bit version of THBImage please go to the bin32/All folder, run YourSetup.cmd and add all remaining files to your setup. Deploy all files to your application.exe folder.
How to deploy 64bit version
To deploy the 64bit version do the same in the bin64/All folder.
How can I create PDF files from TIFF?
The first way is to use the THBPdfDocumentPageWriter object. You find more PDFWriter examples in the THBImage.chm docu Main Classes->THBPDF->Getting Started
Another way to create pdf files from pictures is to use the THBImageEdit object directly.
ie.FileFormatSettings.PDFSettings "THBImage", _
Format(Now), _
"THBComponentware", "THBImage", _
strFileDst, strFileDst, "PDF, Picture"
ie.SavePictureMultiToFile arImages, strFileDst, thbifPDF, bAppend
If you search for ‘SaveAllAcquiredImages’ in the demo projects you will find a complete example.
But the first step is always the same, it is loading the tiff file into a THBImageEdit object using LoadPictureFromFile.
So what’s the difference between these to techniques.
When using THBImageEdit to create PDF files you have to prepare an array of all pages of the file. This means you have to store all pages in memory before writing out the PDF file. Which works fine with files less then 10 pages but will cause an out of memory error with larger pdf documents.
Another limitation is that you can’t add additional PDF elements like text or Hyperlinks.
The second technique is to use the THBPdfDocumentPageWriter object.
Here you can add page by page, add additional PDF elements like text or hyperlink and write out the file when finished.
pdf.PageWriter.AddLayerImage(UtilsFactory.CreateTHBRectd(0,0,100,100), "Main", "Layer1", ie);
pdf.PageWriter.AddLayerImage(UtilsFactory.CreateTHBRectd(0,0,100,200), "Main2", "Layer2", ie2);
pdf.PageWriter.AddLayerImage(UtilsFactory.CreateTHBRectd(0,0,100,300), "Main3", "Layer3", ie3);
The code can be easily ported to Vb.Net, Vb6, C++
How can I convert PDF to TIFF using THBImage?
The THBPdfDocument object can read pdf files and extract the contained pictures and store them into a new picture files.
So we don’t render the pdf on our own, we just read out the pictures.
You can find some PDF examples in the docu at Main Classes -> THBPdf -> Getting Started
When I display the first image in my C# .NET application the mouse wheel zooming works correctly but when I display additional images the mouse wheel zooming fails.
The MouseWheel zooming just works if the focus is on the C# .NET THBView control. To enforce this use the Focus function.
thbView1.Focus();
MouseWheel support for the .NET control was added in 5.0.5.6. It was always part of the ActiveX/Com version but not in the .Net version.
How can get a rectangle selection from the user and use it for imageprocessing filters?
One way is to let the user draw a rectangle.
The rectangle will never be stored in a vector layer, instead we just extract its coordinates after creation.
Here is a complete VB.NET Windows Forms demo using THBImage to get the selection from the user. crop.zip
' let the user draw a rectangle
ThbView1.Commands.Start(thbCommand.thbCmdRect)
After drawing it we get the NewGeometry event
In the previous THBImage version this event was called NewRegion. Starting from THBImage 5.0 vector objects are called geometry objects.
The new rectangle geometry object will be passed to this event and we have the option to either store it within a THBVector layer for viewing or to simply extract its parameters.
Private Sub ThbView1_EventNewGeometry(ByVal geometry As THB.THBGeometry) Handles ThbView1.EventNewGeometry
Try
Crop(geometry)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
This simple example extracts the rectangle bounds and crops out the rectangle part of the image.
Here we assume that you added a picture layer before.
Dim rcBounds As THBRectd
Dim rcBoundsPixel As THBRect
'We need a rectangle geometry object
If geometry.CoordinatesCount <> 2 Then
MsgBox("Invalid Fence!")
Exit Sub
End If
' we need the bounds of the geometry object
rcBounds = geometry.Bounds
Using ie As THBImageEdit = ThbView1.Layers.FirstTHBImageEditObject
' convert the world units to pixel
rcBoundsPixel = ie.Cnv.WorldToPixelRc(rcBounds)
'Create a new image from the cropped part
Using ieCrop As THBImageEdit = ie.ImageProcessing.CropIntoNewObjectRc(rcBoundsPixel)
' we show the cropped picture in the viewer
Using vl As THBViewLayer = ieCrop.InterfaceITHBViewLayer
vl.Name = "PictureLayer"
ThbView1.Layers.ClearAndAdd(vl)
End Using
ThbView1.Zoom.Fit()
End Using
End Using



RSS News Feed