I ont un tableau à 2 dimensions qui est plein de 1 et de 0, commeCarrés Trouver dans un tableau
0 0 0 0 0 0 0 0 0 0
0 0 1 1 1 1 1 1 0 0
0 0 1 0 0 0 0 1 0 0
0 0 1 0 0 0 0 1 0 0
0 0 1 0 0 0 0 1 0 0
0 0 1 1 1 1 1 1 0 0
0 0 0 0 0 0 0 0 0 0
Vous pouvez voir qu'il ya une place dans e tableau. J'essaye de faire une fonction qui fera un rectangle ou une liste de rectangles basés sur le carré. Ainsi, l'exemple reviendriez un rectangle comme
rect.x = 2
rect.y = 1
rect.width = 7
rect.height = 5
Ceci est le code que j'ai maintenant mais DOE pas juste retour quoi que ce soit
Dim rects As New List(Of Rectangle)
For imgWidth As Integer = 0 To bow.GetUpperBound(0)
For imgHeight As Integer = 0 To bow.GetUpperBound(1)
If bow(imgWidth, imgHeight) = 1 Then
If bow(imgWidth + 1, imgHeight) = 1 And
bow(imgWidth + 2, imgHeight) = 1 And
bow(imgWidth, imgHeight + 1) = 1 And
bow(imgWidth, imgHeight + 2) = 1 Then
Dim r As New Rectangle
With r
.X = imgWidth
.Y = imgHeight
End With
For rectWidth As Integer = imgWidth To bow.GetUpperBound(0)
If bow(rectWidth, imgHeight) = 0 Then
r.Width = bow(rectWidth - 1, imgHeight)
End If
Next
For rectHeight As Integer = imgHeight To bow.GetUpperBound(1)
If bow(imgWidth, rectHeight) = 0 Then
r.Height = bow(rectHeight - 1, imgHeight)
End If
Next
rects.Add(r)
End If
End If
Next
Next
De plus, le tableau doit être en mesure d'avoir plus d'un carré.
Pouvez-vous donner plus de détails sur votre problème au-delà de «ça ne rapporte rien»? Qu'avez-vous essayé? – JoshD
Quand j'ai essayé d'ajouter des points de rupture, mais les boucles qui trouvent la largeur et la hauteur retournent toujours 0 – giodamelio
@giodamelio: est ce devoir? Si non, à quoi sert-il et pourquoi? – JoshD