How do i search a picturebox for a certain color in vb.net?
Lets say i got a black image with 50 white pixels, and then i want to count the number of white pixels in the image?
Printable View
How do i search a picturebox for a certain color in vb.net?
Lets say i got a black image with 50 white pixels, and then i want to count the number of white pixels in the image?
Pleeease!! Someone, help me... :cry:
of the top of my head
VB Code:
Import System.Drawing Dim b as Bitmap b = picture1.Image 'might need a cast 'loop x y b.Width-1 b.Height-1 b.getPixel(x,y)
Thx Deadeyes! So far it works. Now to the point where i want to get the colorvalue of each pixel.
In vb 6 i got the decimal colorvalue from 0 to 1650000 something. I want to use the same in vb.net but i dont know how. In my case i want for example search every pixel that got a colorvalue of 65535 ( thats a yellow color ) and each time i find a pixel with that value i will count that pixel. Did you get that?
GetPixel returns a Color which has a method ToARGB() I think that returns a value that is the same as the long value in VB6.
actuall the A stands for Alpha does VB6 store the Alpha value?
Color also has R G and B properties which return bytes so some messing around could give the value your looking for.
There is a ColorTranslater class which has static methods like:
ToWin32
ToHTML
ToOle
one of them will have to work
Thx alot. I will try it when im coming home from work.. I will let you know how i solve it.:thumb:
in .NET u can (as far as my knowledge goes) only getpixel of a bitmap. to do use urbitmap.getpixel (x,y).
Do you need to get a precise number of white pixels, or just an estimate?Quote:
Originally Posted by Libero
An estimate would be an order of magnitude faster, just check every 3rd column and every third row and you can multiply up to get your estimate. Depends of you reasons for counting them. :)
just make a loop PS my code sucks dont copy it
x=1
y=1
loop until y=50
urbitmap.getpixel(x,y)=z
x=x+1
if x=50 then
y=y+1
x=1
print z
end if
ok this is completely non-functional. if ne1 wants to make soemthing that works out of this its fine by me. its just to give u an idea
VB Code:
Dim x,y, whiteCount as integer for y = 0 to pic.height - 1 for x = 0 to pic.width - 1 if pic.getpixel(x,y) = color.white then whiteCount += 1 next x next y