Hi, Guys!
How can I change a value of a color to his black&white value?
Thank you,
Arie.
Printable View
Hi, Guys!
How can I change a value of a color to his black&white value?
Thank you,
Arie.
VB Code:
Private Function GetBVPixel(colour As Long) As Integer Dim r, g, b As Integer Dim averagec As Integer r = colour And 255 g = (colour / 256) And 255 b = colour / 65536 'get the average colour of those RGB values averagec = (r + g + b) / 3 GetBVPixel = averagec 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:
Dim p As Integer Picture1.ScaleMode = vbPixels For y% = 0 To Picture1.ScaleHeight For x% = 0 To Picture1.ScaleWidth p = GetBVPixel(Picture1.Point(x%, y%)) Picture1.PSet (x%, y%), RGB(p, p, p) Next Next
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.
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.
Thank you,
Arie.
now.at/ariecoolsite
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