我已将C#代码转换为VB.NET并出现以下错误。反正有没有让它发挥作用?
第一次错误
VB.NET'Char'值无法转换为'Integer'。使用 'Microsoft.VisualBasic.AscW'将字符解释为Unicode 值或'Microsoft.VisualBasic.Val'将其解释为数字。
charValue = text(System.Math.Max(System.Threading.Interlocked.Increment(charIndex), charIndex - 1))
完整的功能代码
Public Shared Function embedText(text As String, bmp As Bitmap) As Bitmap
Dim charValue As Integer = 0
charValue = text(System.Math.Max(System.Threading.Interlocked.Increment(charIndex), charIndex - 1))
Select Case pixelElementIndex Mod 3
Case 0
If True Then
If state__1 = State.Hiding Then
' the rightmost bit in the character will be (charValue % 2)
' to put this value instead of the LSB of the pixel element
' just add it to it
' recall that the LSB of the pixel element had been cleared
' before this operation
R += charValue Mod 2
' removes the added rightmost bit of the character
' such that next time we can reach the next one
charValue /= 2
End If
End If
Exit Select
Case 1
If True Then
If state__1 = State.Hiding Then
G += charValue Mod 2
charValue /= 2
End If
End If
Exit Select
Case 2
If True Then
If state__1 = State.Hiding Then
B += charValue Mod 2
charValue /= 2
End If
bmp.SetPixel(j, i, Color.FromArgb(R, G, B))
End If
Exit Select
End Select
pixelElementIndex += 1
If state__1 = State.Filling_With_Zeros Then
' increment the value of zeros until it is 8
zeros += 1
End If
Next
Next
Next
Return bmp
End Function
' convert the character value from int to char
Dim c As Char = CChar(charValue)
第二次错误
预期输入
Application.Run(New Project1())
帮我解决这些错误。
答案 0 :(得分:0)
尝试第一条错误消息:
创建一个整数类型说
Dim intValue As Integer
然后将您的char值传递给它
intValue = Asc(charValue)
或
intValue = AscW(charValue)
对于第二个选项,您可能想尝试这个
intValue = Val(charValue)