Results 1 to 11 of 11

Thread: Scanning pixels??

  1. #1

    Thread Starter
    Hyperactive Member Libero's Avatar
    Join Date
    Jun 2000
    Location
    Swedish viking
    Posts
    460

    Unhappy Scanning pixels??

    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?

  2. #2

    Thread Starter
    Hyperactive Member Libero's Avatar
    Join Date
    Jun 2000
    Location
    Swedish viking
    Posts
    460
    Pleeease!! Someone, help me...

  3. #3
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196
    of the top of my head
    VB Code:
    1. Import System.Drawing
    2.  
    3. Dim b as Bitmap
    4.  b = picture1.Image 'might need a cast
    5.  'loop x y b.Width-1 b.Height-1
    6.  b.getPixel(x,y)

  4. #4

    Thread Starter
    Hyperactive Member Libero's Avatar
    Join Date
    Jun 2000
    Location
    Swedish viking
    Posts
    460
    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?

  5. #5
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196
    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.

  6. #6
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196
    There is a ColorTranslater class which has static methods like:
    ToWin32
    ToHTML
    ToOle

    one of them will have to work

  7. #7

    Thread Starter
    Hyperactive Member Libero's Avatar
    Join Date
    Jun 2000
    Location
    Swedish viking
    Posts
    460
    Thx alot. I will try it when im coming home from work.. I will let you know how i solve it.

  8. #8
    Lively Member
    Join Date
    Mar 2005
    Posts
    66

    Re: Scanning pixels??

    in .NET u can (as far as my knowledge goes) only getpixel of a bitmap. to do use urbitmap.getpixel (x,y).

  9. #9
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Scanning pixels??

    Quote Originally Posted by Libero
    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?
    Do you need to get a precise number of white pixels, or just an estimate?

    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.
    I don't live here any more.

  10. #10
    Lively Member
    Join Date
    Mar 2005
    Posts
    66

    Re: Scanning pixels??

    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

  11. #11
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Scanning pixels??

    VB Code:
    1. Dim x,y, whiteCount as integer
    2. for y = 0 to pic.height - 1
    3. for x = 0 to pic.width - 1
    4. if pic.getpixel(x,y) = color.white then whiteCount += 1
    5. next x
    6. next y
    I don't live here any more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width