指针(Of Byte)c#对vb.net的问题 [英] Pointer(Of Byte) c# to vb.net problems

查看:90
本文介绍了指针(Of Byte)c#对vb.net的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我已经尝试将c#转换为vb.net而且我似乎遇到了错误类型'指针'未定义,任何帮助?



 ' 识别潜在的字形 
公共 功能识别(image As UnmanagedImage,rect 作为矩形, ByRef 置信度作为 Single As Byte (,)
Dim glyphStartX As 整数 = rect.Left
Dim glyphStartY 作为 整数 = rect 。最佳
Dim glyphWidth 作为 整数 = rect.Width
Dim glyphHeight As Integer = rect.Height
Dim cellWidth As Integer = glyphWidth / glyphSize
Dim cellHeight As 整数 = glyphHeight / glyphSize
Dim cellOffsetX As 整数 = CInt (cellWidth * 0 2
Dim cellOffsetY As 整数 = CInt (cellHeight * 0 2
Dim cellScanX As 整数 = CInt (cellWidth * 0 6
Dim cellScanY As 整数 = CInt (cellHeight * 0 . 6
Dim cellScanArea 正如 整数 = cellScanX * cellScanY
Dim cellIntensity 作为 整数(,)= 整数(glyphSize - 1 ,glyphSize - 1 ){}
Dim stride 作为 整数 = image.Stride
Dim srcBase 作为 指针( 字节 = CType (image.ImageData.ToPointer(),指针( 字节))+(glyphStartY + cellOffsetY)* stride + glyphStartX + cellOffsetX
Dim srcLine As 指针( 字节
Dim src As 指针( Of Byte
对于 gi 作为 整数 = 0 glyphSize - 1
srcLine = srcBase + cellHeight * gi * stride
对于 y 作为 整数 = 0 cellScanY - 1
对于 gj 作为 整数 = 0 glyphSize - 1
src = srcLine + cellW idth * gj
Dim x As Integer = 0
x< cellScanX
cellIntensity(gi,gj)+ = src.Target
x + = 1
src + = 1
结束
下一步
srcLine + = stride
下一步
下一步

' 计算每个字形单元格的值并设置
' 字形对小区信心最小值的信心
< span class =code-keyword> Dim glyphValues As Byte (,)= < span class =code-keyword>新 字节(glyphSize - 1 ,glyphSize - 1 ){}
confidence = 1 .0F
对于 gi 正如 整数 = 0 glyphSize - 1
对于 gj As 整数 = 0 glyphSize - 1
Dim fullness As 单个 = CSng (cellIntensity(gi,gj)/ 255 )/ cellScanArea
Dim conf 作为 = CSng ( System.Math.Abs​​(丰满度 - 0 5 ))+ 0 .5F
glyphValues(gi,gj)= CByte If ((丰满度)> 0 .5F), 1 0 ))
如果 conf<置信度然后
置信度= conf
结束 如果
下一步
下一步
< span class =code-keyword>返回 glyphValues
结束 功能

解决方案

.NET中没有这样的类型。问题与翻译无关。指针本身可以在不安全模式下使用,项目应该有不安全的选项。在其他情况下,.NET使用引用托管指针而不是指针,它们不需要单独的类型(在C#和VB.NET中,但有一个托管C ++ / CLI中的指针语法,因为使用了引用类型,它们仅通过引用使用,因此不需要单独的语法(在C ++ / CLI中很难伪造,用于匹配常规C ++语法)。



此外,对于图像处理,很少需要指针(不安全)方法。我不知道你到底在做什么,但请看: http:/ /msdn.microsoft.com/en-us/library/system.drawing.bitmap.lockbits.aspx [ ^ ]。



现在,关于翻译。您提到了从C#到VB.NET的翻译,但实际上显示了VB.NET代码。



无论如何,在进行翻译之前,你应该检查你想翻译的代码是否值得翻译。您可以轻松地自动执行从C#到VB.NET或VB.NET到C#的翻译:







祝你好运,

-SA

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?

' 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

解决方案

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


这篇关于指针(Of Byte)c#对vb.net的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆