Re: manipulating bitmaps

[ Follow Ups ] [ Post Followup ] [ Return To Messageboard ] [ FAQ ]


Posted by Kevin Wilson on October 27, 2003 at 07:55:27:

In Reply to: Re: manipulating bitmaps posted by Rich on October 25, 2003 at 13:20:04:

>>You could get the color with "GetPixel"... then use the following
>>function to convert the color to GrayScale:
>>
>>Public Function GrayScale(ByVal lColor As Long) As Long
>>  GrayScale = ((77& * (lColor And &HFF&) + _
>>                150& * (lColor And &HFF00&) \ &H100& + _
>>                28& * ((lColor And &HFF0000) \ &H10000)) \ 256&) * &H10101
>>End Function
>>
>>Then, once the color is grayscale, convert the color to
>>RGB values like so:
>>
>>Public Sub SplitRGB(ByVal lColor As Long, _
>>    ByRef lRed As Long, _
>>    ByRef lGreen As Long, _
>>    ByRef lBlue As Long)
>>  lRed = lColor And &HFF
>>  lGreen = (lColor And &HFF00&) \ &H100&
>>  lBlue = (lColor And &HFF0000) \ &H10000
>>End Sub
>>
>>Then test each value of Red, Gree, Blue to see if 
>>it is above the threshhold you mentioned (0 - 255).
>>
>>Kevin
>
>
>Hi, I couldn't get the splitRGB function to work, compile error argument not optional
>option explicit
>Dim Col As Long, rBlue As Long, rRed As Long, rGreen As Long
>
>Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
>If Button = vbLeftButton Then
>
>Picture1.BackColor = Picture2.Point(X, Y)
>Col = Picture1.Point(5, 5)
>GrayScale Col
>SplitRGB GrayScale, rRed, rGreen, rBlue' 'Greyscale is highlighted in this
>Else
>End If
>End Sub
>
>Am I using it wrong?
>thanx, Rich


Your SYNTAX is incorrect.  Try the following code:


Option Explicit
Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
   Dim Col     As Long
   Dim GrayScl As Long
   Dim rRed    As Long
   Dim rGreen  As Long
   Dim rBlue   As Long
   If Button = vbLeftButton Then
      Col = Picture2.Point(X, Y)
      Picture1.BackColor = Col
      GrayScl = GrayScale(Col)
      SplitRGB GrayScl, rRed, rGreen, rBlue  ' 'Greyscale is highlighted in this
   Else
   End If
End Sub
Public Sub SplitRGB(ByVal lColor As Long, ByRef lRed As Long, ByRef lGreen As Long, ByRef lBlue As Long)
   lRed = lColor And &HFF
   lGreen = (lColor And &HFF00&) \ &H100&
   lBlue = (lColor And &HFF0000) \ &H10000
End Sub
Public Function GrayScale(ByVal lColor As Long) As Long
   GrayScale = ((77& * (lColor And &HFF&) + _
                 150& * (lColor And &HFF00&) \ &H100& + _
                 28& * ((lColor And &HFF0000) \ &H10000)) \ 256&) * &H10101
End Function


Kevin




Follow Ups:



Post A Followup

Name:

E-Mail:

Subject:

Message:


Optional Link URL:

Link Title:

Optional Image URL:


   



[ Follow Ups ] [ Post Followup ] [ Return To Messageboard ] [ FAQ ]