Translasion af VB to C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dafnie
    New Member
    • Sep 2010
    • 2

    #1

    Translasion af VB to C#

    Hi there

    I'm trying to make a routine with the SimpleOCR API.
    But they only give me an eksampel in VB. Can anyone translate this to C#
    The code has be found at http://www.simpleocr.c om/Help.asp.

    The line just below is the hardest, I think the rest is possible to translate for me.

    ret = objOCR.OCRSetOu tputHandlerX(Ad dressOf myOutputHandler )

    Thanks

    Dafnie/Denmark

    Code:
    Sub DoOCR (filename as String)
    'Basic function to perform OCR on a multi-page TIFF image file.
    
    Dim objOCR as SimpleOCR     'SimpleOCR object
    Dim ret, img, imgSet, i as Long      'Function return value, single image pointer, multiple image pointer, page counter
    Dim strOCRResult as String     'String  variable to hold OCR result
    
    Set objOCR = New SimpleOCR
    
    ret = objOCR.OCRSetOutputHandlerX(AddressOf myOutputHandler)
    if isnull(ret) then
         'Error occurred
    end if
    
    imgSet = objOCR.LoadMultipleImgX(filename)
    if isnull(imgSet) then
         'Error occurred
    end if
    
    objOCR.SetLanguageX(ENGLISH,".")     'Set language to English
    objOCR.SetOutputModeX(OM_TEXT)     'Set output mode to Text
    
    For i = 1 to objOCR.GetNBImagesX(imgSet)
    
        img = objOCR.GetImage(imgSet,i)          'Get the current page
        ret = objOCR.OCRX(img,0)               'Perform OCR on page
        if ret > 0 then
             'Error occurred
        end if
    
    Next
    
    MsgBox strOCRResult
    
    objOCR.FreeMultipleImgX img
    
    End Sub
    
    Sub myoutputhandler(ByVal infotype As Integer, ByVal param As Integer)
    'This simple output handler sets the strOCRResult string to the OCR result.
    
    'Return Value
    'None
    
    'Parameters
    'infotype - Contant indicating type of information contained in param.
    'param - data from OCR engine. See SetOCROutputHandler declaration for details.
    
    'Comments
    'Output handler must be declared in BAS modules and not form code
    'since the AddressOf method requires it for passing as a pointer
    
    On Error Resume Next 'required to avoid propagating DLL errors to VB
    
    Select Case infotype
    Case OT_TEXT
    strOCRResult = strOCRResult + CStr(Chr(param))
    
    Case OT_ENDL
    strOCRResult = strOCRResult + "\\n"
    End Select
    
    End Sub
  • Anton Zinchenko
    New Member
    • Sep 2010
    • 16

    #2
    Code:
    ret = objOCR.OCRSetOutputHandlerX(AddressOf myOutputHandler)
    Will be
    Code:
    ret = objOCR.OCRSetOutputHandlerX(new MyDelegateType(myOutputHandler))
    Replace the "MyDelegateType " by your type...

    Comment

    • dafnie
      New Member
      • Sep 2010
      • 2

      #3
      Thanks for the reply... :-)

      Comment

      • TamusJRoyce
        New Member
        • Apr 2008
        • 108

        #4
        http://www.developerfusion.com/tools.../vb-to-csharp/. I wouldn't use it for large project, but things like this example seem like the perfect candidate.

        VB.Net <> C#. LinQ doesn't always work yet. But hey. Takes the work out of hand-coding the translation.

        Comment

        Working...