После преобразования кода с C# в vb.net указатели и небезопасный код возникают, и из-за приложения мне нужно их использовать, поэтому я прочитал о создании собирать и ссылаться на него в приложении vb.net. Я до сих пор не знаю, как это сделать. Указатель (байт) ПроблемаСсылка на C# в сборе из-за проблем с преобразованием vb.net
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
Так я создал C# проекта и помещен кодом оригинального C# части кода в нем пространстве имен CTCAM:
public interface interfaceCTCAM
{
int Recognize(UnmanagedImage image, Rectangle rect, out float confidence);
}
public class Class1
{
public byte[,] Recognize(UnmanagedImage image, Rectangle rect, out float confidence)
{
int glyphSize = 5;
int glyphStartX = rect.Left;
int glyphStartY = rect.Top;
int glyphWidth = rect.Width;
int glyphHeight = rect.Height;
int cellWidth = glyphWidth/glyphSize;
int cellHeight = glyphHeight/glyphSize;
int cellOffsetX = (int)(cellWidth * 0.2);
int cellOffsetY = (int)(cellHeight * 0.2);
int cellScanX = (int)(cellWidth * 0.6);
int cellScanY = (int)(cellHeight * 0.6);
int cellScanArea = cellScanX * cellScanY;
int[,] cellIntensity = new int[glyphSize, glyphSize];
unsafe
{
int stride = image.Stride;
byte* srcBase = (byte*)image.ImageData.ToPointer() +
(glyphStartY + cellOffsetY) * stride +
glyphStartX + cellOffsetX;
byte* srcLine;
byte* src;
for (int gi = 0; gi < glyphSize; gi++)
{
srcLine = srcBase + cellHeight * gi * stride;
for (int y = 0; y < cellScanY; y++)
{
for (int gj = 0; gj < glyphSize; gj++)
{
src = srcLine + cellWidth * gj;
for (int x = 0; x < cellScanX; x++, src++)
{
cellIntensity[gi, gj] += *src;
}
}
srcLine += stride;
}
}
}
// calculate value of each glyph's cell and set
// glyphs' confidence to minim value of cell's confidence
byte[,] glyphValues = new byte[glyphSize, glyphSize];
confidence = 1f;
for (int gi = 0; gi < glyphSize; gi++)
{
for (int gj = 0; gj < glyphSize; gj++)
{
float fullness = (float)
(cellIntensity[gi, gj]/255)/cellScanArea;
float conf = (float)System.Math.Abs(fullness - 0.5) + 0.5f;
glyphValues[gi, gj] = (byte)((fullness > 0.5f) ? 1 : 0);
if (conf < confidence)
confidence = conf;
}
}
return glyphValues;
}
}
После того, как я сделал, что я удалил «признал «функция из кода vb и импортировала созданную библиотеку« Импортирует CTCAM.Class1 ».
Так что в приложении VB, позже в моем коде и ошибке отображается, и вот где я не уверен, куда идти сейчас.
Dim glyphValues As Byte(,) = Recognize(glyphImage, New Rectangle(0, 0, glyphImage.Width, glyphImage.Height), confidence)
Слово «признают» подсвечивается следующей информация об ошибке: «Ссылка на неразделяемый член требует ссылок на объект.»
Любая помощь будет отличной.
Большое спасибо, Пит