Public Function Area(ByVal c As Integer, ByVal Coefficente As Integer, ByVal point As Point) As List(Of Integer)
Dim Points As New List(Of Integer)
Dim NewPoints As New List(Of Integer)
Dim ColoreAttuale, SostCol As Color
Dim Col_Oggetto As Color
Dim ArrayPoint As New List(Of Integer)
Dim Punti As New List(Of Point)
Dim NewPunti As New List(Of Point)
SostCol = Color.Violet
'
Points.Add(c)
Dim bSrc As Bitmap = DirectCast(Immagine.Clone(), Bitmap)
Dim imgModificata As Bitmap = DirectCast(immagineRed.Clone, Bitmap)
' GDI+ still lies to us - the return format is BGR, NOT RGB.
Dim bmData As BitmapData = imgModificata.LockBits(New Rectangle(0, 0, immagineRed.Width, immagineRed.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb)
Dim bmSrc As BitmapData = bSrc.LockBits(New Rectangle(0, 0, bSrc.Width, bSrc.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb)
Dim SrcScan0 As System.IntPtr = bmSrc.Scan0
Dim stride As Integer = bmData.Stride
Dim Scan0 As System.IntPtr = bmData.Scan0
Dim bytes As Integer = (immagineRed.Width * immagineRed.Height * 3) - 2
Dim p2(bytes - 1) As Byte
Dim bytes1 As Integer = (immagineRed.Width * immagineRed.Height * 3) - 2
Dim pSrc(bytes1 - 1) As Byte
' Copy the RGB values into the array.
System.Runtime.InteropServices.Marshal.Copy(Scan0, p2, 0, bytes)
System.Runtime.InteropServices.Marshal.Copy(SrcScan0, pSrc, 0, bytes1)
Dim nOffset As Integer = stride - bmData.Width * 3
' sicurezza che la variabile "Col_Oggetto" venga inpostata manualmente su un colore di
'un oggetto per evitare la ripetizione della ricerca dei punti inseriti
If Funzione = Funzioni.TrovaOggettiDiUnColore Then
If ColoreOggetto = Nothing Then
Col_Oggetto = Color.FromArgb(p2(c + 2), p2(c + 1), p2(c))
Else
Col_Oggetto = ColoreOggetto
End If
Else
Col_Oggetto = Color.FromArgb(p2(c + 2), p2(c + 1), p2(c))
End If
Oggetto.p_t.Add(point)
Punti.Add(point)
Dim i As Int32
Do
For Each K As Integer In Points
Dim sin As Integer, dest As Integer, sop As Integer, Sot As Integer
Dim J_ As Point, d_ As Point, s_ As Point, ot_ As Point, Score As Point
Score = Punti(i)
'testa il punto a destra di questo
If K > 3 Then
sin = K - 3
J_ = New Point(Score.X - 1, Score.Y)
End If
ColoreAttuale = Color.FromArgb(pSrc(sin + 2), pSrc(sin + 1), pSrc(sin))
If IsNearestColor(Col_Oggetto, ColoreAttuale, CoefficenteOggetto) = True Then 'Funzione Di Confronto Colore con coefficente
If ArrayPoint.IndexOf(sin) = -1 Then
p2(sin + 2) = Color.Red.R
p2(sin + 1) = Color.Red.G
p2(sin) = Color.Red.B
Oggetto.p_t.Add(J_)'oggetto che conterra le coordinate dei punti
NewPunti.Add(J_)
NewPoints.Add(sin)
PuntiInseriti.Add(sin)'Array Di integer Totali
ArrayPoint.Add(sin)
PuntiInseriti.Add(sin + 1)
ArrayPoint.Add(sin + 1)
PuntiInseriti.Add(sin + 2)
ArrayPoint.Add(sin + 2)
End If
Else
p2(sin + 2) = SostCol.R
p2(sin + 1) = SostCol.G
p2(sin) = SostCol.B
End If
If K < (bytes - 3) Then
dest = K + 3
d_ = New Point(Score.X + 1, Score.Y)
End If
ColoreAttuale = Color.FromArgb(pSrc(dest + 2), pSrc(dest + 1), pSrc(dest))
If IsNearestColor(Col_Oggetto, ColoreAttuale, CoefficenteOggetto) = True Then
If ArrayPoint.IndexOf(dest) = -1 Then
p2(dest + 2) = Color.Red.R
p2(dest + 1) = Color.Red.G
p2(dest) = Color.Red.B
Oggetto.p_t.Add(d_)
NewPunti.Add(d_)
NewPoints.Add(dest)
PuntiInseriti.Add(dest)
ArrayPoint.Add(dest)
PuntiInseriti.Add(dest + 1)
ArrayPoint.Add(dest + 1)
PuntiInseriti.Add(dest + 2)
ArrayPoint.Add(dest + 2)
End If
Else
p2(dest + 2) = SostCol.R
p2(dest + 1) = SostCol.G
p2(dest) = SostCol.B
End If
If K > (stride + nOffset) Then
sop = K - stride - nOffset
s_ = New Point(Score.X, Score.Y - 1)
End If
ColoreAttuale = Color.FromArgb(pSrc(sop + 2), pSrc(sop + 1), pSrc(sop))
If IsNearestColor(Col_Oggetto, ColoreAttuale, CoefficenteOggetto) = True Then
If ArrayPoint.IndexOf(sop) = -1 Then
p2(sop + 2) = Color.Red.R
p2(sop + 1) = Color.Red.G
p2(sop) = Color.Red.B
Oggetto.p_t.Add(s_)'Oggetto dell'area
NewPunti.Add(s_)
NewPoints.Add(sop)
PuntiInseriti.Add(sop)'Array Di intege Totali
ArrayPoint.Add(sop)
PuntiInseriti.Add(sop + 1)
ArrayPoint.Add(sop + 1)
PuntiInseriti.Add(sop + 2)
ArrayPoint.Add(sop + 2)
End If
Else
p2(sop + 2) = SostCol.R
p2(sop + 1) = SostCol.G
p2(sop) = SostCol.B
End If
If K < (bytes - stride - nOffset) Then
Sot = K + stride + nOffset
ot_ = New Point(Score.X, Score.Y + 1)
End If
If Sot < bytes Then
ColoreAttuale = Color.FromArgb(pSrc(Sot + 2), pSrc(Sot + 1), pSrc(Sot))
If IsNearestColor(Col_Oggetto, ColoreAttuale, CoefficenteOggetto) = True Then
If ArrayPoint.IndexOf(Sot) = -1 Then
p2(Sot + 2) = Color.Red.R
p2(Sot + 1) = Color.Red.G
p2(Sot) = Color.Red.B
Oggetto.p_t.Add(ot_)
NewPunti.Add(ot_)
NewPoints.Add(Sot)
PuntiInseriti.Add(Sot)
ArrayPoint.Add(Sot)
PuntiInseriti.Add(Sot + 1)
ArrayPoint.Add(Sot + 1)
PuntiInseriti.Add(Sot + 2)
ArrayPoint.Add(Sot + 2)
End If
Else
p2(Sot + 2) = SostCol.R
p2(Sot + 1) = SostCol.G
p2(Sot) = SostCol.B
End If
End If
i += 1
Next
Points.Clear()
Points.AddRange(NewPoints)
NewPoints.Clear()
Punti.Clear()
Punti.AddRange(NewPunti)
NewPunti.Clear()
i = 0
Loop Until Points.Count = 0
' Copy the RGB values back to the bitmap
System.Runtime.InteropServices.Marshal.Copy(pSrc, 0, SrcScan0, bytes1)
System.Runtime.InteropServices.Marshal.Copy(p2, 0, Scan0, bytes)
imgModificata.UnlockBits(bmData)
bSrc.UnlockBits(bmSrc)
If (ArrayPoint.Count / 3) > PuntiPerPallino Then
immagineRed = imgModificata
End If
Return ArrayPoint
End Function