counting a colors pixels on picturebox urgent!
Posted on 2005-05-05
Hello, I am currently counting a specific colors number of pixels in an area of a picturebox, if the number is > 175 then I add it to the listbox, however it takes a very long time to count the pixels?? is there any way I can speed the it up? It takes be about 5-10 seconds to scan 1 picture this is very slow...any ideas??
This is my function:
Public Function CountPixels(color As Long, picBox As PictureBox) As Long
Dim x As Long, y As Long
Dim handle As Long, count As Long
Dim Hcolor As Long
' cache form's hDC property
handle = picBox.hdc
For y = 0 To Int(picBox.ScaleY(picBox.ScaleHeight, vbTwips, vbPixels) / 2)
For x = 0 To Int(picBox.ScaleX(picBox.ScaleWidth, vbTwips, vbPixels) / 2)
Hcolor = (GetPixel(handle, x, y))
If Hcolor = color Then
count = count + 1
CountPixels = count