IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Pöinter(Of Bytes) en VB .NET [Débutant]


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Inscrit en
    Octobre 2004
    Messages
    42
    Détails du profil
    Informations forums :
    Inscription : Octobre 2004
    Messages : 42
    Par défaut Pöinter(Of Bytes) en VB .NET
    Bonsoir,

    J'ai essayer de convertir la fonction suivante ecrite en C# grace à plusieurs convertisseurs en ligne :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
     
    private Rectangle searchBitmap(Bitmap smallBmp, Bitmap bigBmp, double tolerance)
    {
        BitmapData smallData = 
          smallBmp.LockBits(new Rectangle(0, 0, smallBmp.Width, smallBmp.Height), 
                   System.Drawing.Imaging.ImageLockMode.ReadOnly, 
                   System.Drawing.Imaging.PixelFormat.Format24bppRgb);
        BitmapData bigData = 
          bigBmp.LockBits(new Rectangle(0, 0, bigBmp.Width, bigBmp.Height), 
                   System.Drawing.Imaging.ImageLockMode.ReadOnly, 
                   System.Drawing.Imaging.PixelFormat.Format24bppRgb);
     
        int smallStride = smallData.Stride;
        int bigStride = bigData.Stride;
     
        int bigWidth = bigBmp.Width;
        int bigHeight = bigBmp.Height - smallBmp.Height + 1;
        int smallWidth = smallBmp.Width * 3;
        int smallHeight = smallBmp.Height;
     
        Rectangle location = Rectangle.Empty;
        int margin = Convert.ToInt32(255.0 * tolerance);
     
        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;
     
            for (int y = 0; y < bigHeight; y++)
            {
                for (int x = 0; x < bigWidth; x++)
                {
                    byte* pBigBackup = pBig;
                    byte* pSmallBackup = pSmall;
     
                    //Look for the small picture.
                    for (int i = 0; i < smallHeight; i++)
                    {
                        int j = 0;
                        matchFound = true;
                        for (j = 0; j < smallWidth; j++)
                        {
                            //With tolerance: pSmall value should be between margins.
                            int inf = pBig[0] - margin;
                            int sup = pBig[0] + margin;
                            if (sup < pSmall[0] || inf > pSmall[0])
                            {
                                matchFound = false;
                                break;
                            }
     
                            pBig++;
                            pSmall++;
                        }
     
                        if (!matchFound) break;
     
                        //We restore the pointers.
                        pSmall = pSmallBackup;
                        pBig = pBigBackup;
     
                        //Next rows of the small and big pictures.
                        pSmall += smallStride * (1 + i);
                        pBig += bigStride * (1 + i);
                    }
     
                    //If match found, we return.
                    if (matchFound)
                    {
                        location.X = x;
                        location.Y = y;
                        location.Width = smallBmp.Width;
                        location.Height = smallBmp.Height;
                        break;
                    }
                    //If no match found, we restore the pointers and continue.
                    else
                    {
                        pBig = pBigBackup;
                        pSmall = pSmallBackup;
                        pBig += 3;
                    }
                }
     
                if (matchFound) break;
     
                pBig += bigOffset;
            }
        }
     
        bigBmp.UnlockBits(bigData);
        smallBmp.UnlockBits(smallData);
     
        return location;
    }
    Trouvé ici

    Donne :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    Private Function searchBitmap(smallBmp As Bitmap, bigBmp As Bitmap, tolerance As Double) As Rectangle
    	Dim smallData As BitmapData = smallBmp.LockBits(New Rectangle(0, 0, smallBmp.Width, smallBmp.Height), System.Drawing.Imaging.ImageLockMode.[ReadOnly], System.Drawing.Imaging.PixelFormat.Format24bppRgb)
    	Dim bigData As BitmapData = bigBmp.LockBits(New Rectangle(0, 0, bigBmp.Width, bigBmp.Height), System.Drawing.Imaging.ImageLockMode.[ReadOnly], System.Drawing.Imaging.PixelFormat.Format24bppRgb)
    
    	Dim smallStride As Integer = smallData.Stride
    	Dim bigStride As Integer = bigData.Stride
    
    	Dim bigWidth As Integer = bigBmp.Width
    	Dim bigHeight As Integer = bigBmp.Height - smallBmp.Height + 1
    	Dim smallWidth As Integer = smallBmp.Width * 3
    	Dim smallHeight As Integer = smallBmp.Height
    
    	Dim location As Rectangle = Rectangle.Empty
    	Dim margin As Integer = Convert.ToInt32(255.0 * tolerance)
    
    	Dim pSmall As Pointer(Of Byte) = CType(CType(smallData.Scan0, Pointer(Of System.Void)), Pointer(Of Byte))
    	Dim pBig As Pointer(Of Byte) = CType(CType(bigData.Scan0, Pointer(Of System.Void)), Pointer(Of Byte))
    
    	Dim smallOffset As Integer = smallStride - smallBmp.Width * 3
    	Dim bigOffset As Integer = bigStride - bigBmp.Width * 3
    
    	Dim matchFound As Boolean = True
    
    	For y As Integer = 0 To bigHeight - 1
    		For x As Integer = 0 To bigWidth - 1
    			Dim pBigBackup As Pointer(Of Byte) = pBig
    			Dim pSmallBackup As Pointer(Of Byte) = pSmall
    
    			'Look for the small picture.
    			For i As Integer = 0 To smallHeight - 1
    				Dim j As Integer = 0
    				matchFound = True
    				For j = 0 To smallWidth - 1
    					'With tolerance: pSmall value should be between margins.
    					Dim inf As Integer = pBig(0) - margin					Dim sup As Integer = pBig(0) + margin
    					If sup < pSmall(0) OrElse inf > pSmall(0) Then
    						matchFound = False
    						Exit For
    					End If
    
    					pBig += 1
    					pSmall += 1
    				Next
    
    				If Not matchFound Then
    					Exit For
    				End If
    
    				'We restore the pointers.
    				pSmall = pSmallBackup
    				pBig = pBigBackup
    
    				'Next rows of the small and big pictures.
    				pSmall += smallStride * (1 + i)
    				pBig += bigStride * (1 + i)
    			Next
    
    			'If match found, we return.
    			If matchFound Then
    				location.X = x
    				location.Y = y
    				location.Width = smallBmp.Width
    				location.Height = smallBmp.Height
    				Exit For
    			Else
    				'If no match found, we restore the pointers and continue.
    				pBig = pBigBackup
    				pSmall = pSmallBackup
    				pBig += 3
    			End If
    		Next
    
    		If matchFound Then
    			Exit For
    		End If
    
    		pBig += bigOffset
    	Next
    
    	bigBmp.UnlockBits(bigData)
    	smallBmp.UnlockBits(smallData)
    
    	Return location
    End Function
    J'ai remplacé les déclarations "Pointer(Of Byte)" par des "IntPtr" comme conseillé.
    Le probléme j'ai le message
    Structure 'System.IntPtr' cannot be indexed because it has no default property
    qui correspond aux lignes 43,44 et 45 avec les Pointer(0).
    C'est bien les Pointer(0) qui ne lui plaisent pas, je pense les convertir avec la class "Marshal", mais je ne vois pas comment l'utiliser pour le faire.

    Merci

    Ren

  2. #2
    Membre averti
    Inscrit en
    Octobre 2004
    Messages
    42
    Détails du profil
    Informations forums :
    Inscription : Octobre 2004
    Messages : 42
    Par défaut
    Re,

    J'ai essayé d'ajouter 2 bytes en les copiant avec la class Marshall, plus d'erreurs mais retourne rien du tout :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
     
        Private Function searchBitmap(ByVal smallBmp As Bitmap, ByVal bigBmp As Bitmap, ByVal tolerance As Double) As Rectangle
            Dim smallData As BitmapData = smallBmp.LockBits(New Rectangle(0, 0, smallBmp.Width, smallBmp.Height), System.Drawing.Imaging.ImageLockMode.[ReadOnly], System.Drawing.Imaging.PixelFormat.Format24bppRgb)
            Dim bigData As BitmapData = bigBmp.LockBits(New Rectangle(0, 0, bigBmp.Width, bigBmp.Height), System.Drawing.Imaging.ImageLockMode.[ReadOnly], System.Drawing.Imaging.PixelFormat.Format24bppRgb)
     
            Dim smallStride As Integer = smallData.Stride
            Dim bigStride As Integer = bigData.Stride
     
            Dim bigWidth As Integer = bigBmp.Width
            Dim bigHeight As Integer = bigBmp.Height - smallBmp.Height + 1
            Dim smallWidth As Integer = smallBmp.Width * 3
            Dim smallHeight As Integer = smallBmp.Height
     
     
            Dim margin As Integer = Convert.ToInt32(255.0 * tolerance)
     
            Dim pSmall As IntPtr = smallData.Scan0
            Dim pBig As IntPtr = bigData.Scan0
     
            Dim smallOffset As Integer = smallStride - smallBmp.Width * 3
            Dim bigOffset As Integer = bigStride - bigBmp.Width * 3
     
            Dim matchFound As Boolean = True
     
            For y As Integer = 0 To bigHeight - 1
                For x As Integer = 0 To bigWidth - 1
                    Dim pBigBackup As IntPtr = pBig
                    Dim pSmallBackup As IntPtr = pSmall
     
                    Dim pBig0(0) As Byte                                ' ICI
                    Call Marshal.Copy(pBig, pBig0, 0, 0)
     
                    Dim pSmall0(0) As Byte                             ' ET LA
                    Call Marshal.Copy(pSmall, pSmall0, 0, 0)
     
                    'Look for the small picture.
                    For i As Integer = 0 To smallHeight - 1
                        Dim j As Integer = 0
                        matchFound = True
                        For j = 0 To smallWidth - 1
                            'With tolerance: pSmall value should be between margins.
                            Dim inf As Integer = pBig0(0) - margin
                            Dim sup As Integer = pBig0(0) + margin
                            If sup < pSmall0(0) OrElse inf > pSmall0(0) Then
                                matchFound = False
                                Exit For
                            End If
     
                            pBig += 1
                            pSmall += 1
                        Next
     
                        If Not matchFound Then
                            Exit For
                        End If
     
                        'We restore the pointers.
                        pSmall = pSmallBackup
                        pBig = pBigBackup
     
                        'Next rows of the small and big pictures.
                        pSmall += smallStride * (1 + i)
                        pBig += bigStride * (1 + i)
                    Next
     
                    'If match found, we return.
                    If matchFound Then
                        loca.X = x
                        loca.Y = y
                        loca.Width = smallBmp.Width
                        loca.Height = smallBmp.Height
                        Exit For
                    Else
                        'If no match found, we restore the pointers and continue.
                        pBig = pBigBackup
                        pSmall = pSmallBackup
                        pBig += 3
                    End If
                Next
     
                If matchFound Then
                    Exit For
                End If
     
                pBig += bigOffset
            Next
     
            bigBmp.UnlockBits(bigData)
            smallBmp.UnlockBits(smallData)
     
            Return loca
        End Function
    Si quelqu'un a une idée, merci..

  3. #3
    Membre extrêmement actif
    Inscrit en
    Avril 2008
    Messages
    2 573
    Détails du profil
    Informations personnelles :
    Âge : 65

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 573
    Par défaut
    bonjour Ren97
    Le VB6 avait horreur de manipuler les adresses memoires des variables malgre l'existence non officielle des varptr,varstr & varArray.
    Le VB.Net a reintroduit le pointeur "safe" avec IntPtr car sa manipulation se fait via les appels de l'API .Net de Marshalling (System.Runtime.InteropServices).
    Neamoins on peut acceder au contenu d'un Intpr via les fonctions:
    - Marshal.ReadByte(ptr, offset) si la donnee est un Byte (octet)
    - Marshal.ReadInt32(ptr, offset) si la donnee est un Integer(Int32).
    -ptr etant l'adresse de depart
    -offset la distance par rapport à l'adresse de depart(un Integer).
    Mais comment incrementer le pointeur -ptr- qu'on a recupere avec InPtr that is question?.
    Sachant que sur le x86 un pointeur IntPtr tient sur 4 octets comme un Integer on va le caster en Integer ,l'incrementer (de 1 saut de 1 byte ,de 2 saut de 2 bytes....etc),puis puis ...le recaster en Intpr.....

    "Et voilà" comme aiment dire les english lorsqu'ils font une grande decouverte..!
    Pourquoi le code qui manipule directement les adresses memoires est "unsafe" c.à.d non sur?
    Parce que le compilateur ne peut pas verifier si les zones memoires accedes sont valides à la compilation ....
    voici d'abord un code qui illustre la manip des ptr avec MarshalAs et qui inverse les couleurs d'une image:....

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
     
    'ajoute 
    '-1 button
    '-1 picturebox pour image originale
    '-1 picturebox pour image avec couleur complementee
    '-une image en resource
    Imports System.Drawing.Imaging
    Imports System.Runtime.InteropServices
    Public Class Form1
     
        Private bmp As Bitmap
        Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
     
            Me.pictureBox1.Image = My.Resources.zebra
            bmp = My.Resources.zebra
            If (Invert(bmp)) Then
                Me.pictureBox2.Image = bmp
            End If
     
        End Sub
        Public Shared Function Invert(ByVal b As Bitmap) As Boolean
     
            'GDI+ still lies to us - the return format is BGR, NOT RGB. 
            Dim bmData As BitmapData = b.LockBits(New Rectangle(0, 0, b.Width, b.Height), _
               ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb)
            'Rappel:stride = nb octets par largeur image pour chaque ligne image. 
            Dim stride As Integer = bmData.Stride
            Dim Scan0 As IntPtr = bmData.Scan0
     
            Try
     
     
                Dim p As IntPtr = bmData.Scan0
                Dim sz As Integer = IntPtr.Size
                Form1.Label1.Text = sz.ToString
                'on soustrait de stride le nombre d'octets correspondant aux 3 octets 
                'de couleurs RGB dans une ligne => nb octets de "padding" 
                Dim nOffset As Integer = stride - b.Width * 3
                Dim nWidth As Integer = b.Width * 3
     
                Dim currentByte As Byte
                Dim incrementPtr As Int32 = 0
                For y As Integer = 0 To b.Height - 1
     
                    For x As Integer = 0 To nWidth - 1
                        'RED,GREEN,BLUE =>sont des Octets compris entre 0 et 255  
                        'lit un octet couleur à l'adresse pointe par -p-offset 0
                        currentByte = Marshal.ReadByte(p, 0)
                        'le complemente par rapport 255  
                        currentByte = 255 - currentByte
                        'on reecrit octet couleur à la meme adresse
                        Marshal.WriteByte(p, currentByte)
     
                        'caste le IntPtr en integer (tiens tiens il ya une fonction disponible...)
                        incrementPtr = p.ToInt32
                        'incremente l'entier de 1 (octet suivant)
                        incrementPtr = incrementPtr + 1
                        'le reconvertit en IntPtr et au suivant
                        p = CType(incrementPtr, IntPtr)
     
                    Next
                    'idem
                    incrementPtr = p.ToInt32
                    ' saut cette fois d'un nb d'octets egal aux "octets de padding"
                    'pour aller aux octets de couleur suivants
     
                    incrementPtr = incrementPtr + nOffset
                    p = CType(incrementPtr, IntPtr)
                Next
            Catch ex As AccessViolationException
                MessageBox.Show(ex.Message & ex.Source & ex.StackTrace)
            End Try
     
            b.UnlockBits(bmData)
     
            Return True
        End Function
    End Class
    et voici ton code modifie un tantinet avec MarshalAs.......

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
     
    'ajoute 
    '-1 button
    '-1 picturebox pour image "merge avec la sous-image".
    '-1 picturebox pour la sous-image originale
    '-un label pour afficher le rectangle et ses coordonnees
    '-les 2 images sont en resources
     
    Imports System.Drawing.Imaging
    Imports System.Runtime.InteropServices
     
    Public Class Form1
        Public Sub New()
     
            ' Cet appel est requis par le Concepteur Windows Form.
            InitializeComponent()
     
            ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
     
        End Sub
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Me.PictureBox1.Image = My.Resources.BigWithSmall
            Me.PictureBox2.Image = My.Resources.Small
     
            Dim bigImage As Bitmap = Me.PictureBox1.Image
            Dim smallImage As Bitmap = Me.PictureBox2.Image
            Dim tolerance As Double = 0.2
            Dim rect As Rectangle = searchBitmap(smallImage, bigImage, tolerance)
     
            Me.LabelRect.Text = "Location: " & rect.X.ToString & " , " & rect.Y.ToString & vbCrLf
            Me.LabelRect.Text = Me.LabelRect.Text & "WxH :" & rect.Width.ToString & " , " & rect.Height.ToString
     
             End Sub
        Private Function searchBitmap(ByVal smallBmp As Bitmap, ByVal bigBmp As Bitmap, ByVal tolerance As Double) As Rectangle
            Dim smallData As BitmapData = smallBmp.LockBits(New Rectangle(0, 0, smallBmp.Width, smallBmp.Height), ImageLockMode.[ReadOnly], PixelFormat.Format24bppRgb)
            Dim bigData As BitmapData = bigBmp.LockBits(New Rectangle(0, 0, bigBmp.Width, bigBmp.Height), ImageLockMode.[ReadOnly], PixelFormat.Format24bppRgb)
     
            Dim smallStride As Integer = smallData.Stride
            Dim bigStride As Integer = bigData.Stride
     
            Dim bigWidth As Integer = bigBmp.Width
            Dim bigHeight As Integer = bigBmp.Height - smallBmp.Height + 1
            Dim smallWidth As Integer = smallBmp.Width * 3
            Dim smallHeight As Integer = smallBmp.Height
     
            Dim location As Rectangle = Rectangle.Empty
            Dim margin As Integer = Convert.ToInt32(255.0 * tolerance)
     
     
            'Dim pSmall As Pointer(Of Byte) = CType(CType(smallData.Scan0, Pointer(Of System.Void)), Pointer(Of Byte))
            'Dim pBig As Pointer(Of Byte) = CType(CType(bigData.Scan0, Pointer(Of System.Void)), Pointer(Of Byte))
            ' Get the address of the first line.
            Dim pSmall As IntPtr = smallData.Scan0
            Dim pBig As IntPtr = bigData.Scan0
     
            Dim smallOffset As Integer = smallStride - smallBmp.Width * 3
            Dim bigOffset As Integer = bigStride - bigBmp.Width * 3
     
            Dim matchFound As Boolean = True
     
            'POUR LISIBILITE DU CODE
            Dim currentByte As Byte
     
            'INCREMENTATION DU POINTEUR -P-
            'NECESSAIRE DE LE CONVERTIR EN ENTIER 32 BIT(INTEGER)
            Dim incrementPtrBig As Int32 = 0
            Dim incrementPtrpSmall As Int32 = 0
     
            matchFound = True
            Try
                For y As Integer = 0 To bigHeight - 1
                    For x As Integer = 0 To bigWidth - 1
                        'Dim pBigBackup As Pointer(Of Byte) = pBig
                        'Dim pSmallBackup As Pointer(Of Byte) = pSmall
                        Dim pBigBackup As IntPtr = pBig
                        Dim pSmallBackup As IntPtr = pSmall
     
                        'Look for the small picture.
                        For i As Integer = 0 To smallHeight - 1
                            matchFound = True
                            For j As Integer = 0 To smallWidth - 1
                                'With tolerance: pSmall value should be between margins.
                                'Dim inf As Integer = pBig(0) - margin
                                'Dim sup As Integer = pBig(0) + margin
                                currentByte = Marshal.ReadByte(pBig, 0)
                                Dim inf As Integer = currentByte - margin
                                Dim sup As Integer = currentByte + margin
     
                                'If sup < pSmall(0) OrElse inf > pSmall(0) Then
                                '    matchFound = False
                                '    Exit For
                                'End If
                                If sup < Marshal.ReadByte(pSmall, 0) OrElse inf > Marshal.ReadByte(pSmall, 0) Then
                                    matchFound = False
                                    Exit For
                                End If
     
                                'pBig += 1
                                'IntPtr est converti en integer avant d'etre incrementer de 1
                                'car IntPtr ne supporte les operations arithmetiques
                                '& Caste en IntPtr
                                incrementPtrBig = pBig.ToInt32
                                incrementPtrBig = incrementPtrBig + 1
                                pBig = CType(incrementPtrBig, IntPtr)
     
                                'pSmall += 1
                                'idem
                                incrementPtrpSmall = pSmall.ToInt32
                                incrementPtrpSmall = incrementPtrpSmall + 1
                                pSmall = CType(incrementPtrpSmall, IntPtr)
     
                            Next
     
                            If Not matchFound Then
                                Exit For
                            End If
     
                            'We restore the pointers.
                            pSmall = pSmallBackup
                            pBig = pBigBackup
     
                            'Next rows of the small and big pictures.
                            'increment est egal cette fois =>smallStride * (1 + i)
                            'pSmall += smallStride * (1 + i)
                            incrementPtrpSmall = pSmall.ToInt32
                            incrementPtrpSmall = incrementPtrpSmall + smallStride * (1 + i)
                            pSmall = CType(incrementPtrpSmall, IntPtr)
     
                            'pBig += bigStride * (1 + i)
                            incrementPtrBig = pBig.ToInt32
                            incrementPtrBig = incrementPtrBig + bigStride * (1 + i)
                            pBig = CType(incrementPtrBig, IntPtr)
                        Next
     
                        'If match found, we return.
                        If matchFound Then
                            location.X = x
                            location.Y = y
                            location.Width = smallBmp.Width
                            location.Height = smallBmp.Height
                            Exit For
                        Else
                            'If no match found, we restore the pointers and continue.
                            pBig = pBigBackup
                            pSmall = pSmallBackup
     
                            'pBig += 3
                            'increment est egal cette fois =>3
                            incrementPtrBig = pBig.ToInt32
                            incrementPtrBig = incrementPtrBig + 3
                            pBig = CType(incrementPtrBig, IntPtr)
                        End If
                    Next
     
                    If matchFound Then
                        Exit For
                    End If
     
                    'pBig += bigOffset
     
                    incrementPtrBig = pBig.ToInt32
                    incrementPtrBig = incrementPtrBig + bigOffset
                    pBig = CType(incrementPtrBig, IntPtr)
     
                Next
            Catch ex As AccessViolationException
                MessageBox.Show(ex.Message & ex.Source & ex.StackTrace)
            End Try
     
            bigBmp.UnlockBits(bigData)
            smallBmp.UnlockBits(smallData)
     
            Return location
        End Function
     
     
    End Class
    Les fautes d'orthographes son brevetes comme aime à le dire un collegue du forum !
    bon code..................

  4. #4
    Membre averti
    Inscrit en
    Octobre 2004
    Messages
    42
    Détails du profil
    Informations forums :
    Inscription : Octobre 2004
    Messages : 42
    Par défaut
    Merci MABROUKI, marche nickel.

    Pour les fautes, il est vrai qu'après plusieurs heures devant l'écran, on est un peu fatigué.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. comparer 2 tableaux de bytes en vb.net
    Par niceen dans le forum VB.NET
    Réponses: 6
    Dernier message: 29/04/2008, 19h03
  2. [VB.NET] Tableau de bytes Lecture/Ecriture
    Par BenoitM dans le forum Windows Forms
    Réponses: 3
    Dernier message: 05/04/2005, 09h51
  3. [C++.NET] Conversion Byte*/Byte[]
    Par SteelBox dans le forum VC++ .NET
    Réponses: 2
    Dernier message: 13/02/2005, 19h12
  4. [VB.NET] Conversion int-> bytes sur 4 octets
    Par SteelBox dans le forum Windows Forms
    Réponses: 11
    Dernier message: 09/01/2005, 22h08
  5. [VB.NET] Fichier text et byte()
    Par nmerydem dans le forum Windows Forms
    Réponses: 6
    Dernier message: 10/11/2004, 17h28

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo