指针(Of Byte)c#对vb.net的问题 [英] Pointer(Of Byte) c# to vb.net problems
本文介绍了指针(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#的翻译:
- 使用在线翻译之一。我不想指出任何一个特定的;请看这里: http://bit.ly/XFdX2G [ ^ ]。
在我的观察中,这个比其他人更准确:http://converter.telerik.com/ [ ^ ]。- 现在,这是一个非常精彩的离线解决方案:使用开源ILSpy:
http://www.ilspy.net/ [ ^ ],
http://en.wikipedia.org/wiki/.NET_Reflector [ ^ ]。
首先,您需要编译项目并获取已编译的程序集。它编译为CIL:
http://en.wikipedia.org/wiki/Common_Intermediate_Language [ ^ ]。
您可以将程序集加载到ILSpy中并对其进行反汇编。它有输出语言选项。选择C#或VB.NET,然后重新编译所需的部分代码。你已经完成了。
祝你好运,
-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:
- Use one of on-line translators. I don't want to point to any particular one; just look here: http://bit.ly/XFdX2G[^].
In my observations, this one is more accurate than some others: http://converter.telerik.com/[^].- Now, a really wonderful off-line solution: use open-source ILSpy:
http://www.ilspy.net/[^],
http://en.wikipedia.org/wiki/.NET_Reflector[^].
First, you need to compile the project and obtain a compiled assembly. It is compiled to CIL:
http://en.wikipedia.org/wiki/Common_Intermediate_Language[^].
You can load assembly into ILSpy and disassemble it. It has the option for output language. Select either C# or VB.NET, and recompile the part of code you need. You are done.
Good luck,
—SA
这篇关于指针(Of Byte)c#对vb.net的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文