VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form frmMain 
   Caption         =   "UCBioBSPCOM_ExportDemoVB"
   ClientHeight    =   5925
   ClientLeft      =   120
   ClientTop       =   420
   ClientWidth     =   7335
   LinkTopic       =   "Form1"
   ScaleHeight     =   5925
   ScaleWidth      =   7335
   StartUpPosition =   3  'Windows ⺻
   Begin VB.CommandButton cmdOK 
      Caption         =   "OK"
      Height          =   375
      Left            =   5880
      TabIndex        =   16
      Top             =   5400
      Width           =   1335
   End
   Begin VB.Frame Frame2 
      Caption         =   "2) Import from ..."
      Height          =   5055
      Left            =   3720
      TabIndex        =   17
      Top             =   120
      Width           =   3495
      Begin VB.OptionButton radioImportTemplateType 
         Caption         =   "400 bytes Template"
         Height          =   255
         Index           =   0
         Left            =   480
         TabIndex        =   10
         Top             =   480
         Value           =   -1  'True
         Width           =   2655
      End
      Begin VB.OptionButton radioImportTemplateType 
         Caption         =   "800 bytes Template"
         Height          =   255
         Index           =   1
         Left            =   480
         TabIndex        =   11
         Top             =   840
         Width           =   2655
      End
      Begin VB.OptionButton radioImportTemplateType 
         Caption         =   "320 bytes Template"
         Height          =   255
         Index           =   2
         Left            =   480
         TabIndex        =   12
         Top             =   1200
         Width           =   2655
      End
      Begin VB.OptionButton radioImportTemplateType 
         Caption         =   "256 bytes Template"
         Height          =   255
         Index           =   3
         Left            =   480
         TabIndex        =   13
         Top             =   1560
         Width           =   2655
      End
      Begin VB.CommandButton cmdImport 
         Caption         =   "Import && Verify"
         Height          =   375
         Left            =   720
         TabIndex        =   15
         Top             =   4440
         Width           =   2055
      End
      Begin VB.OptionButton radioImportTemplateType 
         Caption         =   "FMR Standard"
         Height          =   255
         Index           =   4
         Left            =   480
         TabIndex        =   14
         Top             =   1920
         Width           =   2655
      End
      Begin VB.Line Line3 
         BorderColor     =   &H80000000&
         X1              =   120
         X2              =   3360
         Y1              =   4200
         Y2              =   4200
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "1) Export to ..."
      Height          =   5055
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   3495
      Begin VB.OptionButton radioExportTemplateType 
         Caption         =   "WSQ Image"
         Height          =   255
         Index           =   8
         Left            =   480
         TabIndex        =   19
         Top             =   3720
         Width           =   2535
      End
      Begin VB.OptionButton radioExportTemplateType 
         Caption         =   "RAW Image"
         Height          =   255
         Index           =   5
         Left            =   480
         TabIndex        =   6
         Top             =   3000
         Width           =   2655
      End
      Begin VB.OptionButton radioExportTemplateType 
         Caption         =   "BMP Image"
         Height          =   255
         Index           =   6
         Left            =   480
         TabIndex        =   7
         Top             =   3240
         Width           =   2655
      End
      Begin VB.OptionButton radioExportTemplateType 
         Caption         =   "JPG Image"
         Height          =   255
         Index           =   7
         Left            =   480
         TabIndex        =   8
         Top             =   3480
         Width           =   2655
      End
      Begin VB.OptionButton radioExportTemplateType 
         Caption         =   "FMR Standard"
         Height          =   255
         Index           =   4
         Left            =   480
         TabIndex        =   5
         Top             =   1920
         Width           =   2655
      End
      Begin VB.CommandButton cmdExport 
         Caption         =   "Capture && Export"
         Height          =   375
         Left            =   720
         TabIndex        =   9
         Top             =   4440
         Width           =   2055
      End
      Begin VB.OptionButton radioExportTemplateType 
         Caption         =   "256 bytes Template"
         Height          =   255
         Index           =   3
         Left            =   480
         TabIndex        =   4
         Top             =   1560
         Width           =   2655
      End
      Begin VB.OptionButton radioExportTemplateType 
         Caption         =   "320 bytes Template"
         Height          =   255
         Index           =   2
         Left            =   480
         TabIndex        =   3
         Top             =   1200
         Width           =   2655
      End
      Begin VB.OptionButton radioExportTemplateType 
         Caption         =   "800 bytes Template"
         Height          =   255
         Index           =   1
         Left            =   480
         TabIndex        =   2
         Top             =   840
         Width           =   2655
      End
      Begin VB.OptionButton radioExportTemplateType 
         Caption         =   "400 bytes Template"
         Height          =   255
         Index           =   0
         Left            =   480
         TabIndex        =   1
         Top             =   480
         Value           =   -1  'True
         Width           =   2655
      End
      Begin VB.Line Line2 
         BorderColor     =   &H80000000&
         X1              =   120
         X2              =   3360
         Y1              =   4200
         Y2              =   4200
      End
      Begin VB.Label Label1 
         Caption         =   "Image export ..."
         Height          =   255
         Left            =   240
         TabIndex        =   18
         Top             =   2640
         Width           =   2295
      End
      Begin VB.Line Line1 
         BorderColor     =   &H80000000&
         X1              =   120
         X2              =   3360
         Y1              =   2400
         Y2              =   2400
      End
   End
   Begin MSComDlg.CommonDialog CommonDialog 
      Left            =   120
      Top             =   5280
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Declaration global variables
Dim WithEvents objUCBioBSP As UCBioBSPCOMLib.UCBioBSP
Attribute objUCBioBSP.VB_VarHelpID = -1

Dim objDevice As IDevice                ' Device object
Dim objExtraction As IExtraction        ' Extraction object
Dim objMatching As IMatching            ' Matching object
Dim objFPData As IFPData                ' FPData object
Dim objFPImage As IFPImage              ' FPImage object


Private Sub cmdExport_Click()
    objDevice.Open &HFF ' Auto
    
    If objUCBioBSP.ErrorCode = 0 Then
        
        objExtraction.Capture 1
        'objExtraction.Enroll
        
        
        ' You can use Enroll method instead of Capture method..
        ' objExtraction.Enroll Null
        
        If objUCBioBSP.ErrorCode = 0 Then
            Dim biFIR() As Byte
            Dim biTemplate() As Byte
            Dim nDataSize As Long
            Dim szFileName As String
            Dim szOrgFileName As String
            Dim szFilter As String
            Dim szExt As String
            Dim nFileNumber As Integer
            Dim nTemplateType As Integer
            Dim bImage As Boolean
            Dim nImgType As Integer
                        
            bImage = False
            szFilter = "UCT Files (*.uct)|*.uct|All Files|*.*||"
            szExt = ".uct"
                        
            ' Get binary encoded FIR data
            biFIR = objExtraction.FIR
            
            ' Set Template type
            For m = 0 To 8
                If radioExportTemplateType.Item(m).Value Then
                    Select Case m
                    Case 0
                        nTemplateType = 400
                    Case 1
                        nTemplateType = 800
                    Case 2
                        nTemplateType = 320
                    Case 3
                        nTemplateType = 256
                    Case 4
                        nTemplateType = 1   ' FMR
                        
                    Case 5
                        bImage = True
                        nImgType = 1    ' 1 = Raw
                        szFilter = "Raw Files (*.raw)|*.raw|All Files|*.*||"
                        szExt = ".raw"
                    Case 6
                        bImage = True
                        nImgType = 2    ' 2 = BMP
                        szFilter = "BMP Files (*.bmp)|*.bmp|All Files|*.*||"
                        szExt = ".bmp"
                    Case 7
                        bImage = True
                        nImgType = 3    ' 3 = JPG
                        szFilter = "JPG Files (*.jpg)|*.jpg|All Files|*.*||"
                        szExt = ".jpg"
                    Case 8
                        bImage = True
                        nImgType = 4    ' 4 = WSQ
                        szFilter = "WSQ Files (*.wsq)|*.wsq|All Files|*.*||"
                        szExt = ".wsq"
                    End Select
                    
                    Exit For
                End If
            Next
            
            ' Save dialog box
            CommonDialog.CancelError = True
            CommonDialog.Filter = szFilter
            CommonDialog.FileName = ""
            On Error Resume Next
            CommonDialog.ShowSave
            
            If Err.Number = cdlCancel Then
                On Error GoTo 0
                Exit Sub
            End If
            
            ' Set filename
            szFileName = CommonDialog.FileName
            szOrgFileName = szFileName
            
            If szFileName <> "" Then
                If bImage = False Then
                    ' Export data
                    objFPData.Export biFIR, nTemplateType
                    
                    If objUCBioBSP.ErrorCode = 0 Then
                        
                        ' Get finger count & sample number
                        nFingerCnt = objFPData.TotalFingerCount
                        nSampleNum = objFPData.SampleNumber
                        
                        For f = 0 To nFingerCnt - 1
                            nFingerID = objFPData.FingerID(f)
                            For s = 0 To nSampleNum - 1
                                nDataSize = objFPData.FPSampleDataLength(nFingerID, s)
                                biTemplate = objFPData.FPSampleData(nFingerID, s)
                                
                                ' Make new filename
                                szFileName = Left(szOrgFileName, Len(szOrgFileName) - 4)
                                szFileName = szFileName & "_" & CStr(nFingerID) & "_" & CStr(s) & ".uct"
                                If Dir(szFileName, vbNormal) <> "" Then
                                    Kill szFileName
                                End If
                        
                                ' Save
                                nFileNumber = FreeFile
                                Open szFileName For Binary Access Write As #nFileNumber
                                Put #nFileNumber, , biTemplate
                                Close #nFileNumber
                            Next s
                        Next f
                        
                        MsgBox$ "Succeeded to save template file(s)."
                    Else
                        MsgBox$ "Failed to export data (" & CStr(objUCBioBSP.ErrorCode) & ")"
                    End If
                Else
                    ' Export image data
                    objFPImage.Export
                    
                    If objUCBioBSP.ErrorCode = 0 Then
                        
                        ' Get finger count & sample number
                        nFingerCnt = objFPImage.TotalFingerCount
                        
                        For f = 0 To nFingerCnt - 1
                            nFingerID = objFPImage.FingerID(f)
                            ' Make new filename
                            szFileName = Left(szFileName, Len(szFileName) - 4)
                            szFileName = szFileName & "_" & CStr(f) & szExt
                            If Dir(szFileName, vbNormal) <> "" Then
                                Kill szFileName
                            End If
                            
                            objFPImage.Save szFileName, nImgType, nFingerID
                            If objUCBioBSP.ErrorCode <> 0 Then
                                Exit For
                            End If
                        Next f
                    End If
                    
                    If objUCBioBSP.ErrorCode = 0 Then
                        MsgBox$ "Succeeded to save image file(s)."
                    Else
                        MsgBox$ "Failed to save image data (" & CStr(objUCBioBSP.ErrorCode) & ")"
                    End If
                
                End If
            End If
        End If
    End If
    
    objDevice.Close &HFF
End Sub

Private Sub cmdImport_Click()
    Dim szFileName As String
    
    ' Load dialog box
    CommonDialog.CancelError = True
    CommonDialog.Filter = "UCT Files (*.uct)|*.uct|All Files|*.*||"
    On Error Resume Next
    CommonDialog.ShowOpen
    
    If Err.Number = cdlCancel Then
        On Error GoTo 0
        Exit Sub
    End If
        
    szFileName = ""
    szFileName = CommonDialog.FileName
    
    If szFileName <> "" Then
        Dim biTemplate() As Byte
        Dim nDataSize As Long
        Dim nFileNumber As Integer
        Dim nTemplateType As Integer
        
        nFileNumber = FreeFile
        
        ' Load file
        Open szFileName For Binary As nFileNumber
        nDataSize = LOF(nFileNumber)
        ReDim biTemplate(nDataSize)
        Get #nFileNumber, , biTemplate
        Close #nFileNumber
        
        ' Set Template type
        For m = 0 To 5
            If radioImportTemplateType.Item(m).Value Then
                Select Case m
                Case 0
                    nTemplateType = 400
                Case 1
                    nTemplateType = 800
                Case 2
                    nTemplateType = 320
                Case 3
                    nTemplateType = 256
                Case 4
                    nTemplateType = 1   ' FMR
                End Select
                
                Exit For
            End If
        Next
            
        ' Import data
        objFPData.Import 1, nFingerID, 1, nTemplateType, nDataSize, biTemplate
        
        If objUCBioBSP.ErrorCode = 0 Then
            ' Verify
            objDevice.Open &HFF ' Auto
            objMatching.Verify objFPData.FIR
            objDevice.Close &HFF
            
            If objMatching.MatchingResult Then
                MsgBox$ "Succeeded to verify!"
            Else
                MsgBox$ "Failed to verify!"
            End If
        Else
            MsgBox$ "Failed to import data (" & CStr(objFPData.ErrorCode) & ")"
        End If
    End If
End Sub

Private Sub cmdOK_Click()
    End
End Sub


Private Sub Form_Load()
    ' Create UCBioBSP object
    Set objUCBioBSP = New UCBioBSPCOMLib.UCBioBSP
    Set objDevice = objUCBioBSP.Device
    Set objExtraction = objUCBioBSP.Extraction
    Set objMatching = objUCBioBSP.Matching
    Set objFPData = objUCBioBSP.FPData
    Set objFPImage = objUCBioBSP.FPImage
    
    ' Check initialize object
    If objUCBioBSP.ErrorCode = 0 Then
        ' Get UCBioBSP version
        frmMain.Caption = "UCBioBSPCOM_ExportDemo for VB - UCBioBSP Version : " & objUCBioBSP.MajorVersion & "." & objUCBioBSP.MinorVersion
    Else
        MsgBox objUCBioBSP.ErrorDescription & " [" & objUCBioBSP.ErrorCode & "]", vbOKOnly
    End If
End Sub

