For a math project I place 21 random points in a picture and after that I scan the surface to connect the dots via a line in a specific fashion. 2018R4 Windows10
This code runs in de Paint event of the Canvas
Dim PointRandom As New Random Dim CanvasPicture As New Picture(Canvas1.Width,Canvas1.Height,32) Dim X,Y,OldX,OldY As Integer Dim CanvasSurface As RGBSurface Dim PointsFound As Integer = 0 CanvasPicture.Graphics.ForeColor = RGB(0,0,0) For i As Integer = 0 To 20 Dim PixelPoint As New OvalShape PixelPoint.Width = 1 PixelPoint.Height = 1 X = PointRandom.InRange(0,Canvas1.Width) Y = PointRandom.Inrange(0,Canvas1.Height) CanvasPicture.Graphics.DrawObject(PixelPoint,X,Y) Next CanvasSurface = CanvasPicture.RGBSurface For J As Integer = 0 To CanvasPicture.Width-1 For K As Integer = 0 To CanvasPicture.Height-1 If CanvasSurface.Pixel(J,K) = RGB(0,0,0) Then PointsFound = PointsFound+1 End If If PointsFound > 1 Then CanvasPicture.Graphics.DrawLine(OldX,OldY,J,K) End If OldX = J OldY = K Next Next Canvas1.Backdrop = CanvasPicture MsgBox(Str(PointsFound))
The RGBSurface.Pixel should return 21 pixels, but I got around 970? Looks like it detects more pixels with this RGB(0,0,0) value, but that shouldn't be possible.
ps the code block doesn't format the code anymore?