twain ocr函数返回空字节

时间:2014-06-30 09:39:55

标签: vb.net bytearray ocr twain twaindotnet

我有以下代码:

    ddlResultFormat.Items.Add("Text")

    dynamicDotNetTwain1.LoadImage("C:\Users\elj\Desktop\3b072e9b-76b4-4776-bd3c-5984074d8ecd.png")
    Dim r = dynamicDotNetTwain1.GetImage(dynamicDotNetTwain1.CurrentImageIndexInBuffer).Width.ToString()
    Dim l = dynamicDotNetTwain1.GetImage(dynamicDotNetTwain1.CurrentImageIndexInBuffer).Height.ToString()
    Dim languageFolder As String
    languageFolder = "C:\Program Files (x86)\Dynamsoft\Dynamic .NET TWAIN 5.2 Trial\Samples\Bin\"
    Dim languages As New Dictionary(Of String, String)
    languages.Add("English", "eng")
    Me.dynamicDotNetTwain1.OCRTessDataPath = languageFolder
    Me.dynamicDotNetTwain1.OCRLanguage = "English"

    Dim ocrResultFormat As Dynamsoft.DotNet.TWAIN.OCR.ResultFormat
    ocrResultFormat = CType(System.Enum.Parse(GetType(Dynamsoft.DotNet.TWAIN.OCR.ResultFormat), Val("&H" & 0)), Dynamsoft.DotNet.TWAIN.OCR.ResultFormat)
    Me.dynamicDotNetTwain1.OCRResultFormat = ResultFormat.Text

    Dim strDllPath As String
    strDllPath = "C:\Program Files (x86)\Dynamsoft\Dynamic .NET TWAIN 5.2 Trial\Redistributable\OCRResources\"
    dynamicDotNetTwain1.OCRDllPath = strDllPath

    If (Me.dynamicDotNetTwain1.CurrentImageIndexInBuffer < 0) Then
        Dim jajajja = "Please load an image before doing OCR!"
    End If

    Dim sbytes As Byte()
    sbytes = Me.dynamicDotNetTwain1.OCR(Me.dynamicDotNetTwain1.CurrentSelectedImageIndicesInBuffer)

我面临的问题是sbytes字节数组总是设置为空,尽管缓冲区中的indice是正确的,路径和dll很好地实现但是转换为字节数组没有成功我没有得到任何异常,但字节的长度是0

任何想法如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

请更新以下代码行,然后重试。

Me.dynamicDotNetTwain1.OCRLanguage = "eng" 'not English