J’aimerais connaître l’équivalent VB.NET du code C # suivant:
unsafe { byte* pStart = (byte*)(void*)writeableBitmap.BackBuffer; int nL = writeableBitmap.BackBufferSsortingde; for (int r = 0; r < 16; r++) { for (int g = 0; g < 16; g++) { for (int b = 0; b < 16; b++) { int nX = (g % 4) * 16 + b; int nY = r*4 + (int)(g/4); *(pStart + nY*nL + nX*3 + 0) = (byte)(b * 17); *(pStart + nY*nL + nX*3 + 1) = (byte)(g * 17); *(pStart + nY*nL + nX*3 + 2) = (byte)(r * 17); } } } }
On dirait que ce n’est pas possible.
De ce post
VB.NET est plus ressortingctif que C # à cet égard. Il ne permet en aucun cas l’utilisation de code non sécurisé.
Impossible, car vb.net ne prend pas en charge le code non sécurisé.
VB.NET n’autorise pas l’utilisation de code non sécurisé, mais vous pouvez le faire en toute sécurité:
Dim pStart As IntPtr = AddressOf (writeableBitmap.BackBuffer()) Dim nL As Integer = writeableBitmap.BackBufferSsortingde For r As Integer = 0 To 15 For g As Integer = 0 To 15 For b As Integer = 0 To 15 Dim nX As Integer = (g Mod 4) * 16 + b Dim nY As Integer = r * 4 + CInt(g \ 4) Marshal.WriteInt32((pStart + nY * nL + nX * 3 + 0),(b * 17)) Marshal.WriteInt32((pStart + nY * nL + nX * 3 + 1),(g * 17)) Marshal.WriteInt32((pStart + nY * nL + nX * 3 + 2),(r * 17)) Next Next Next
Vous pouvez utiliser ce code sécurisé avec le même résultat
Dim pStart As Pointer(Of Byte) = CType(CType(writeableBitmap.BackBuffer, Pointer(Of System.Void)), Pointer(Of Byte)) Dim nL As Integer = writeableBitmap.BackBufferSsortingde For r As Integer = 0 To 15 For g As Integer = 0 To 15 For b As Integer = 0 To 15 Dim nX As Integer = (g Mod 4) * 16 + b Dim nY As Integer = r * 4 + CInt(g \ 4) (pStart + nY * nL + nX * 3 + 0).Target = CByte(b * 17) (pStart + nY * nL + nX * 3 + 1).Target = CByte(g * 17) (pStart + nY * nL + nX * 3 + 2).Target = CByte(r * 17) Next Next Next