Click here to Skip to main content
15,889,838 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I've tried converting c# to vb.net and i seem to be getting problems the error "Type 'Pointer' is not defined, any help?

VB
' Recognize a potential glyph
    Public Function Recognize(image As UnmanagedImage, rect As Rectangle, ByRef confidence As Single) As Byte(,)
        Dim glyphStartX As Integer = rect.Left
        Dim glyphStartY As Integer = rect.Top
        Dim glyphWidth As Integer = rect.Width
        Dim glyphHeight As Integer = rect.Height
        Dim cellWidth As Integer = glyphWidth / glyphSize
        Dim cellHeight As Integer = glyphHeight / glyphSize
        Dim cellOffsetX As Integer = CInt(cellWidth * 0.2)
        Dim cellOffsetY As Integer = CInt(cellHeight * 0.2)
        Dim cellScanX As Integer = CInt(cellWidth * 0.6)
        Dim cellScanY As Integer = CInt(cellHeight * 0.6)
        Dim cellScanArea As Integer = cellScanX * cellScanY
        Dim cellIntensity As Integer(,) = New Integer(glyphSize - 1, glyphSize - 1) {}
        Dim stride As Integer = image.Stride
        Dim srcBase As Pointer(Of Byte) = CType(image.ImageData.ToPointer(), Pointer(Of Byte)) + (glyphStartY + cellOffsetY) * stride + glyphStartX + cellOffsetX
        Dim srcLine As Pointer(Of Byte)
        Dim src As Pointer(Of Byte)
        For gi As Integer = 0 To glyphSize - 1
            srcLine = srcBase + cellHeight * gi * stride
            For y As Integer = 0 To cellScanY - 1
                For gj As Integer = 0 To glyphSize - 1
                    src = srcLine + cellWidth * gj
                    Dim x As Integer = 0
                    While x < cellScanX
                        cellIntensity(gi, gj) += src.Target
                        x += 1
                        src += 1
                    End While
                Next
                srcLine += stride
            Next
        Next

        ' calculate value of each glyph's cell and set
        ' glyphs' confidence to minim value of cell's confidence
        Dim glyphValues As Byte(,) = New Byte(glyphSize - 1, glyphSize - 1) {}
        confidence = 1.0F
        For gi As Integer = 0 To glyphSize - 1
            For gj As Integer = 0 To glyphSize - 1
                Dim fullness As Single = CSng(cellIntensity(gi, gj) / 255) / cellScanArea
                Dim conf As Single = CSng(System.Math.Abs(fullness - 0.5)) + 0.5F
                glyphValues(gi, gj) = CByte(If((fullness > 0.5F), 1, 0))
                If conf < confidence Then
                    confidence = conf
                End If
            Next
        Next
        Return glyphValues
    End Function
Posted
Comments
Sampath Lokuge 1-Oct-13 10:29am    
Try this tool :http://www.developerfusion.com/tools/convert/vb-to-csharp/

1 solution

There is no such type in .NET. The problem is not related to translations. Pointers themselves can be used in unsafe mode, the project should have unsafe option. In other cases, instead of pointers, .NET uses references or managed pointers, which don't need separate types (in C# and VB.NET, but there is a managed pointer syntax in C++/CLI), because reference types are used instead, which are only used via references, so there is no real need for the separate syntax (which is poorly fake in C++/CLI, used to match "regular" C++ syntax).

Besides, for image manipulations, pointer (unsafe) approach is rarely needed, if ever. I don't know what exactly you are doing, but please see: http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.lockbits.aspx[^].

Now, about translations. You mentioned translations from C# to VB.NET but actually show the VB.NET code.

Anyway, before doing translations, you should check up if the code you want to translate worth translating. You can easily perform translations from C# to VB.NET or VB.NET to C# automatically:



Good luck,
—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900