|
-
Apr 13th, 2002, 08:49 AM
#1
Thread Starter
Fanatic Member
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.
-
Apr 13th, 2002, 11:03 AM
#2
PowerPoster
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
-
Apr 14th, 2002, 07:49 AM
#3
Fanatic Member
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.
-
Apr 14th, 2002, 09:13 AM
#4
Good Ol' Platypus
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)
-
Apr 21st, 2002, 01:07 PM
#5
Thread Starter
Fanatic Member
-
Apr 21st, 2002, 02:28 PM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|