【问题标题】:EZTwain - where is it writing the file too?EZTwain - 它也在哪里写文件?
【发布时间】:2019-03-19 20:45:00
【问题描述】:

一位同事离职时向每个人保证他签入了旧扫描应用程序(VB.NET Win Forms)源代码的最新版本。他没有。编译后的版本运行良好,但签入的版本却不行。使用 Red Gate 的 .NET Reflector 反编译工作版本后,我们得到以下代码。

应用程序使用EZTwain。我期待EZTwain.DibWritePage(num2) 行将文件写入指定的path。它没有。其他一切正常。

文件在哪里? DocLocation = "C:\Scanner\" 并且该文件夹存在。

Private Sub cmdScan_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdScan.Click
    Me.Cursor = Cursors.WaitCursor
    If (Me.SearchList.ListBoxReference.Length = 0) Then
        MessageBox.Show("Please input a Reference before proceeding.", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        Me.SearchList.Focus()
        Me.Cursor = Cursors.Default
    Else
        Dim num As Integer = 1
        Dim str As String = Me.SearchList.ListBoxReference.Replace("/", "-")
        Dim path As String = (My.Settings.DocLocation & str & "_v0001.tif")
        Do While True
            Dim strArray As String()
            If Not File.Exists(path) Then
                Try
                    EZTwain.OrganizationLicense(My.Settings.EZTwainOrganisation, My.Settings.EZTwainKey)
                    EZTwain.SetHideUI(False)
                    EZTwain.SetFileAppendFlag(False)
                    EZTwain.SetJpegQuality(&H4B)
                    EZTwain.SetTiffCompression(2, 7)
                    EZTwain.SetResolution(CInt(Me.cboDefaultResolution.SelectedItem))
                    If EZTwain.OpenDefaultSource Then
                        EZTwain.SetXferCount(-1)
                        EZTwain.SetAutoScan(True)
                        EZTwain.SetMultiTransfer(True)
                        EZTwain.BeginMultipageFile(path)
                        Do While True
                            Dim num2 As System.IntPtr = EZTwain.Acquire(Me.Handle)
                            If (num2 <> 0) Then
                                EZTwain.DibWritePage(num2)
                                EZTwain.DIB_Free(num2)
                                If (EZTwain.State >= 6) Then
                                    Continue Do
                                End If
                            End If
                            EZTwain.CloseSource()
                            EZTwain.EndMultipageFile()
                            Exit Do
                        Loop
                    End If
                    If (EZTwain.LastErrorCode <> 0) Then
                        EZTwain.ReportLastError("Unable to scan.")
                        File.Delete(path)
                        Me.Cursor = Cursors.Default
                    Else
                        If (File.Exists(path) And (FileSystem.FileLen(path) < 20)) Then
                            File.Delete(path)
                        ElseIf File.Exists(path) Then
                            Dim num3 As Double = (CDbl(FileSystem.FileLen(path)) / 1000000)
                            Try
                                strArray = New String() {System.IO.Path.GetFileName(path), " (", num3.ToString("N3"), "Mb ", Convert.ToString(File.GetCreationTime(path)), ")"}
                                Me.lstDocuments.Items.Add(String.Concat(strArray))
                                Me.lstDocuments.Sorted = True
                                If My.Settings.ImagePreview Then
                                    Interaction.Shell((My.Settings.ImageViewer & " " & path), AppWinStyle.MaximizedFocus, False, -1)
                                End If
                                Me.lstDocuments.SelectedIndex = -1
                            Catch exception3 As Exception
                                Dim ex As Exception = exception3
                                CompilerServices.ProjectData.SetProjectError(ex)
                                Dim exception2 As Exception = ex
                                MessageBox.Show(("An error occurred while saving the file." & ChrW(13) & ChrW(10) & "Error - " & exception2.Message & ChrW(13) & ChrW(10) & "Please Try again."), Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Hand)
                                Me.Cursor = Cursors.Default
                                CompilerServices.ProjectData.ClearProjectError()
                                Exit Do
                            End Try
                        End If
                        Me.Cursor = Cursors.Default
                    End If
                Catch exception1 As Exception
                    Dim ex As Exception = exception1
                    CompilerServices.ProjectData.SetProjectError(ex)
                    Dim exception As Exception = ex
                    MessageBox.Show(("An error occurred while scanning the image." & ChrW(13) & ChrW(10) & "Error - " & exception.Message & ChrW(13) & ChrW(10) & "Please Try again."), Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Hand)
                    If File.Exists(path) Then
                        File.Delete(path)
                    End If
                    Me.Cursor = Cursors.Default
                    CompilerServices.ProjectData.ClearProjectError()
                End Try
                Exit Do
            End If
            num += 1
            strArray = New String() {My.Settings.DocLocation, str, "_v", num.ToString.PadLeft(4, "0"c), ".tif"}
            path = String.Concat(strArray)
        Loop
    End If
End Sub

【问题讨论】:

    标签: vb.net scanning


    【解决方案1】:

    路径在这里定义

     (My.Settings.DocLocation & str & "_v0001.tif")
    

    然后在这里交给 twain 软件:

      EZTwain.BeginMultipageFile(path)
    

    如果您查看编译后的应用程序的 exe.config,应该有一个定义为 DocLocation 的节点,给出要使用的路径。

    【讨论】:

    • 噢!忘了参考。给定的路径。 DocLocation 在 app.config 中定义,但文件没有写在那里。为清楚起见,DocLocation = "C:\scanner\" 并且该文件夹存在。
    • 原始帖子已编辑以删除我错误地提及未提供给 EZTwain 的路径。显然是这样,但它仍然没有写入该路径。感谢您发现我的错误。
    • 我们将不胜感激删除反对票,因为这是一个现实世界的问题,并且原始帖子已被编辑以更好地描述该问题。
    • TBH,我看不出任何明显的错误。你用调试器单步执行了吗?
    • 已调试,我自己也找不到任何问题。路径是给定的,但没有文件写入磁盘。我有一种预感,这可能是 TWAIN 和我正在测试的特定扫描仪驱动程序之间的交互(它与新的 Fujitsu SP 1120 捆绑在一起)。富士通通常在 TWAIN 方面表现出色,因此预感不太可能成立。可以肯定的是,我将使用更旧、更高规格的富士通设备进行测试。
    猜你喜欢
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-17
    • 1970-01-01
    相关资源
    最近更新 更多