PDA

View Full Version : finding picture edge in visual basic


jpcar
11-19-02, 12:35
i am currently working on a program which loads field maps to a picture box and performs a model of patch spraying operation. basically a tractor and sprayer drives around the field and by recognising the colour of a pixel it decides whether to spray or not. the maps are in black and white. black for weed white for non weed. i am trying to develop some code which steps around the edge pixels of the field and changes their colour to show that they have been processed. i am very new to programming and any help in this process would be greatly appreciated. thank you

Bruce A. Baasch
11-20-02, 09:14
Hello jpcar,

The "Point" command will allow you to read a pixel.

The "PSet" command will allow you to update a pixel.

I'd recommend setting up a subroutine you could call using X and Y parameters to reduce the amount of coding and debugging. Something like this:
'
' clockwise from upper left
'
ScanPoints(0,Picture.Width,1,0,0,0)
ScanPoints(Picture.Width,Picture.Width,0,0,Picture .Height,1)
ScanPoints(Picture.Width,0,-1,Picture.Height,Picture.Height,0)
ScanPoints(0,0,0,Picture.Height,0,-1)
'
' Routine
'
Public Sub ScanPoints(tmpXFrom as long, tmpXTo as long,
tmpXStep as long, tmpYFrom as long,
tmpYTo as long, tmpYStep as long)
'
' Left/right or Up/down
'
If tmpXStep = 0 then
for lclIndex=tmpYFrom to tmpYTo step tmpYStep
....Point(tmpXFrom,lclindex)....
....PSet(tmpXFrom,lclIndex)....
next
else
for lclIndex=tmpXFrom to tmpXTo step tmpXStep
....Point(lclindex,tmpYFrom)....
....PSet(lclindex,tmpYFrom)....
next
End If

End Sub

This isn't elegant or fast, but should put you in the ballpark.

If you need more information, here are some books that go into graphics:

Instant Visual Basic Animation
The Revolutionary Guide to Bitmapped Graphics
The Visual Basic Programmers Guide to the Win32 API

Good luck,