If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Visual Basic > Argent: Convert Wia 1 code to Wai 2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-18-11, 08:00
Sam76 Sam76 is offline
Registered User
 
Join Date: Jun 2005
Posts: 61
Question Argent: Convert Wia 1 code to Wai 2

hello, i have a problem....
i want to convert code below (wia 1.0) to wia 2.0

Code:
Dim wiaManager As WiaClass = Nothing     ' WIA manager COM object 
Dim wiaDevs As CollectionClass = Nothing ' WIA devices collection COM object 
Dim wiaRoot As ItemClass = Nothing       ' WIA root device COM object 
Dim wiaPics As CollectionClass = Nothing ' WIA collection COM object 
Dim wiaItem As ItemClass = Nothing       ' WIA image COM object 
Try
wiaManager = New WiaClass()   ' create COM instance of WIA manager 
wiaDevs = TryCast(wiaManager.Devices, CollectionClass) ' call Wia.Devices to get all devices 
If (wiaDevs Is Nothing) OrElse (wiaDevs.Count = 0) Then
MessageBox.Show(Me, "No Scanner Devices Found!", "Scanner", MessageBoxButtons.OK, MessageBoxIcon.Stop)
 Return
  End If
Dim selectUsingUI As Object = System.Reflection.Missing.Value     ' = Nothing 
wiaRoot = DirectCast(wiaManager.Create(selectUsingUI), ItemClass) ' let user select device 
If wiaRoot Is Nothing Then  ' nothing to do 
Return
End If
' this call shows the common WIA dialog to let the user select a picture: 
wiaPics = TryCast(wiaRoot.GetItemsFromUI(WiaFlag.SingleImage, WiaIntent.ImageTypeColor), CollectionClass)
If wiaPics Is Nothing Then
    Return
End If
 Dim takeFirst As Boolean = True
 ' this sample uses only one single picture 
 For Each wiaObj As Object In wiaPics
       ' enumerate all the pictures the user selected 
         If takeFirst Then
             ' remove previous picture 
             wiaItem = DirectCast(Marshal.CreateWrapperOfType(wiaObj,   GetType(ItemClass)), ItemClass)
               imageFileName1 = Path.GetTempFileName()  ' create temporary file for image 
                Windows.Forms.Cursor.Current = Cursors.WaitCursor ' could take some time 
                Me.Refresh()
                wiaItem.Transfer(imageFileName1, False)            ' transfer picture to our temporary file 
                Call GetImage1()
 img2 = Image.FromFile(imageFileName1)     ' create Image instance from file 
 takeFirst = False                                 ' first and only one done. 
  End If
Marshal.ReleaseComObject(wiaObj)                      
 Next
Catch ex As Exception
 MessageBox.Show(Me, "Scanning File Failed" & vbCr & vbLf & ex.Message, "Scanning", MessageBoxButtons.OK, MessageBoxIcon.Stop)
 Windows.Forms.Cursor.Current = Cursors.Default
 Finally
 If wiaItem IsNot Nothing Then
      Marshal.ReleaseComObject(wiaItem)
End If
 ' release WIA image COM object 
  If wiaPics IsNot Nothing Then
     Marshal.ReleaseComObject(wiaPics)
  End If
      ' release WIA collection COM object 
 If wiaRoot IsNot Nothing Then
      Marshal.ReleaseComObject(wiaRoot)
   End If
        ' release WIA root device COM object 
If wiaDevs IsNot Nothing Then
     Marshal.ReleaseComObject(wiaDevs)
  End If
   ' release WIA devices collection COM object 
  If wiaManager IsNot Nothing Then
       Marshal.ReleaseComObject(wiaManager)
   End If
   ' release WIA manager COM object 
    Windows.Forms.Cursor.Current = Cursors.Default
            End Try
            Try
                Dim GetPageNo As String
                Dim NoFound As Integer
                Dim TestPageExist As Boolean
                Dim DLoop As Integer
                Dim D2Loop As Integer = DG3.Rows.Count
                For DLoop = 0 To D2Loop
                    If Val(TextNoPages.Text) >= 10 Then
                        GetPageNo = "Page" & TextNoPages.Text
                    Else
                        GetPageNo = "Page" & "0" & TextNoPages.Text
                    End If
                    If DG3.Rows(DLoop).Cells(1).Value = GetPageNo Then
                        NoFound = DLoop
                        TestPageExist = True
                    End If
                    If DLoop = (DG3.Rows.Count - 1) Then
                        Exit For
                    End If
                Next
                If TestPageExist = True Then
                    JPGMaxNo = DLoop + 1
                Else
                    JPGMaxNo = JPGMaxNo + 1
                End If
                'GS = TextNoPages.Text
                x = "Page" & Format(JPGMaxNo, "00")
                x1 = TextActNo.Text
                If DG1.Rows.Count = 0 Then
                    x3 = 1
                Else
                    Select Case CmdSave.Text
                        Case "Save"
                            Call GetMaxAttachSeq()
                            x3 = TextMaxSeq.Text
                        Case "Update"
                            x3 = TextMaxSeq.Text
                    End Select
                End If
                x2 = "Attach" & x3
                y1 = CrtPath & "\" & x1 & "\" & x2
                Directory.CreateDirectory(y1)
                Dim path As String = y1 & "\" & x & ".Jpg"
                Me.Cursor = Cursors.WaitCursor
                img2.Save(path, Imaging.ImageFormat.Jpeg)
                Me.Cursor = Cursors.Default
                FileNam = x
                FileExt = "Jpg"
                OpenPath1 = path
                Call DisposeImage1()

                Call OrderSheetUpdateing()
                ScanOne.Checked = False
                TextNoPages.Text = ""
                FlagAttach = 1
                TextNoPages.Focus()
            Catch ex As Exception
            End Try
            Call IFISData()
            If ISData = False Then
                If FlagAttach = 1 Then
                    Call TestSave()
                End If
            End If
        Else
            If TextNoPages.Text = "" Or Not IsNumeric(TextNoPages.Text) Then
                MessageBox.Show("Check No. Of Pages", "Error", MessageBoxButtons.OK)
                TextNoPages.Focus()
            Else
                If ISFolder = False Then
                    MessageBox.Show("No Folder Found", "Error", MessageBoxButtons.OK)
                End If
            End If
        End If

Can Any one Help Me in That
__________________
Sami Al Damiri ...
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On