Results 1 to 6 of 6

Thread: Converting a color to black&white. How?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636

    Converting a color to black&white. How?

    Hi, Guys!

    How can I change a value of a color to his black&white value?

    Thank you,
    Arie.

  2. #2
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    VB Code:
    1. Private Function GetBVPixel(colour As Long) As Integer
    2. Dim r, g, b As Integer
    3. Dim averagec As Integer
    4. r = colour And 255
    5. g = (colour / 256) And 255
    6. b = colour / 65536
    7. 'get the average colour of those RGB values
    8. averagec = (r + g + b) / 3
    9. GetBVPixel = averagec
    10. End Function

    The value return is Red, Green, and Blue values of the pixel. All 3 will be same so here is its use:
    VB Code:
    1. Dim p As Integer
    2. Picture1.ScaleMode = vbPixels
    3. For y% = 0 To Picture1.ScaleHeight
    4. For x% = 0 To Picture1.ScaleWidth
    5. p = GetBVPixel(Picture1.Point(x%, y%))
    6. Picture1.PSet (x%, y%), RGB(p, p, p)
    7. Next
    8. Next
    Baaaaaaaaah

  3. #3
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    Green is quite a lot lighter than red, but blue is pretty much darker. You can better use weighted values.

    BlackWhite = 1/3 * red + 1/2 * green + 1/6 * blue usually gives a better result.

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    The exact values can be found from a German site... there is a tutorial, translated, by him at Lucky's and it gives a link to his site. I think it's vbempire.de.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636
    Thank you,
    Arie.

    now.at/ariecoolsite

  6. #6
    jim mcnamara
    Guest
    Several of us have posted code on calculating luminosity for a pixel.

    If you want the graphic to look like a B&W photograph, you have to do this to have it look okay.

    For each pixel, get the luminosity value, like 122 - then
    apply it to the pixel - pixel = RGB(122,122,122)

    Here is one thread; the search engine can't find what I posted, but this will get you going.

    http://www.vbforums.com/showthread.p...ght=luminosity

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