Visual Basic - Convert Color Image to greyscale except one color.

Hi,

I have a bit map image (.bmp) image. I want to convert the whole image to grey scale. However set one color not to be converted to its grey scale.
For example I have a color image, I want every color in that image to be converted to it’s greyscale except for the color red. Rgb(255,0,0).
I know there are plenty of activeX controls which will convert a image into grey scale.
Can any one think of a way to convert all colors except one?
The goal is to have the color RED stand out from the greyed out image.

Any help greatly appreciated.
wegwongAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DeadlyTrevCommented:
;Here's a solution, adapted from http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21624357.html

Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long

Private Sub MakeGrey(bgPic as PictureBox, staticColour as long)

    Dim colour As Long
    Dim red As Double, green As Double, blue As Double, grey As Double
    Dim x As Integer, y As Integer

    bgPic.AutoRedraw = True
    bgPic.ScaleMode = vbPixels
    For x = 0 To bgPic.ScaleWidth - 1
        For y = 0 To bgPic.ScaleHeight - 1
            colour = GetPixel(bgPic.hdc, x, y)
            If colour <> staticColour then
                red = colour Mod 256
                green = Int(colour / 256) Mod 256
                blue = Int(colour / 65536)
                'convert using ITU standard
                grey = Int(((red * 222) + (green * 707) + (blue * 71)) / 1000)
                If grey > 255 Then grey = 255
                If grey < 0 Then grey = 0
                SetPixel bgPic.hdc, x, y, RGB(grey, grey, grey)
            End If
        Next
    Next
    bgPic.Refresh

End Sub


To Use:
         MakeGrey picbox, RGB(255, 0, 0)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.