Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# VB.Net中的不安全_C#_Vb.net_Bitmap_Unsafe - Fatal编程技术网

C# VB.Net中的不安全

C# VB.Net中的不安全,c#,vb.net,bitmap,unsafe,C#,Vb.net,Bitmap,Unsafe,我需要将一个函数C#传递给VB.NET,但在C#中,我有类似的东西: unsafe { byte* pSmall = (byte*)(void*)smallData.Scan0; byte* pBig = (byte*)(void*)bigData.Scan0; int smallOffset = smallStride - smallBmp.Width * 3; int bigOffset = bigStride - bigBmp.Width * 3;

我需要将一个函数C#传递给VB.NET,但在C#中,我有类似的东西:

unsafe
{
    byte* pSmall = (byte*)(void*)smallData.Scan0;
    byte* pBig = (byte*)(void*)bigData.Scan0;

    int smallOffset = smallStride - smallBmp.Width * 3;
    int bigOffset = bigStride - bigBmp.Width * 3;

    bool matchFound = true;
    ....
}

我在一些博客上读到,VB.Net中不存在“不安全”。问题是:我可以用什么来代替
不安全的

你读过的博客是正确的,因为在VB.NET中没有办法使用不安全的代码。您似乎想要操作(可能是读取像素数据?)位图文件。在C#中,您可以使用不安全的代码来获得比
GetPixel
方法更高的性能。在VB.NET中,您可以尝试查看

有一个关于如何使用它的例子

Public g_RowSizeBytes作为整数
公共g_PixBytes()作为字节
专用m_BitmapData作为BitmapData
'锁定位图的数据。
公共子锁位图(ByVal bm作为位图)
'锁定位图数据。
矩形尺寸边界=新矩形(_
0,0,bm.宽度,bm.高度)
m_BitmapData=bm.LockBits(边界_
Imaging.ImageLockMode.ReadWrite_
成像.PixelFormat.Format24bppRgb)
g_RowSizeBytes=m_BitmapData.Stride
'为数据分配空间。
Dim total_size As Integer=m_BitmapData.Stride*_
m_BitmapData.Height
重读g_像素字节(总大小)
'将数据复制到g_PixBytes数组中。
封送处理副本(m_BitmapData.Scan0,g_PixBytes_
0,总尺寸)
端接头

该页面还显示了如何解锁位图

我认为这是一个可行的版本:

Dim pSmall作为指针(字节)=CType(CType(smallData.Scan0,
指针(属于System.Void)),指针(属于字节))
Dim pBig作为指针(字节)=CType(CType(bigData.Scan0,
指针(属于System.Void)),指针(属于字节))
将smallOffset设置为整数=smallStride-smallBmp.Width*3
Dim BIGBOFFSET为整数=bigStride-bigBmp.Width*3
找到的匹配项为布尔值=真