|
-
Nov 6th, 2001, 07:34 AM
#1
Thread Starter
Addicted Member
RGB question
Hi guys
Well I need to find out the darkness or brightness of each single pixle of a given image file in my app. To do this I use a picturebox, I load the image into it then I get each pixel’s color using point method. It returns a long RGB number which is the result of merging red, green and blue I guess. 4 example if the point is RGB(192,255,12) it returns 192255012. but there is one problem:
When it is RGB(0,255,0)(pure green) it returns 225
When it is RGB(0,0,255) (pure blue) it returns 225 also
So u see there’s no difference in green and blue using this. So I decided to anlaize these rgb colors. For example I have a point now I want to find out how much red is in it? How much green and how much blue? Do u know how to this?
Thanks aloot
-
Nov 6th, 2001, 07:45 AM
#2
This will do it
VB Code:
lngRed = (lngColor And &HFF&)
lngGreen = (lngColor And &HFF00&) / &H100
lngBlue = (lngColor And &HFF0000) / &H10000
-
Nov 6th, 2001, 07:58 AM
#3
Thread Starter
Addicted Member
can u explain a little more please?
thank u
-
Nov 6th, 2001, 08:07 AM
#4
Weel, I'm not sure what else I can say about the code, it is rather self explaning.
But here goes:
lngColor is a colorcode ie. 192255012
lngRed is the value of red in the RGB colorcode
lngGreen is the value of green in the RGB colorcode
lngBlue is the value of blue in the RGB colorcode
VB Code:
lngRed = (lngColor And &HFF&) 'lngRed is now the value of red
lngGreen = (lngColor And &HFF00&) / &H100 'lngGreen is now the value of green
lngBlue = (lngColor And &HFF0000) / &H10000 'lngBlue is now the value of blue
lngRed, Green and Blue are just varibles, in which I store the value, you can choose your own varibles, debug it or whatever.
The code just does some bitwise operations on the number, and retrieves the bits representing the value of the Red Green and Blue value.
-
Nov 6th, 2001, 08:16 AM
#5
Thread Starter
Addicted Member
u know i'm a little confused with the format of the codelngRed = 4 example i can't see any functions or stuff. i'm looking 4 a way to analize the valum that point method returns to me (lngColor And &HFF&)
hey it seems i'm getting old at 20
-
Nov 6th, 2001, 08:29 AM
#6
OK. I implemented the code that AIS_DK provided into a simple to use function. Add the following code to your Form
VB Code:
Public Enum eRGBcolor
rgbRed = 1
rgbGreen
rgbBlue
End Enum
Private Function GetColorValue(nColor As Long, nReturnColor As eRGBcolor) As Integer
Select Case nReturnColor
Case rgbRed
GetColorValue = (nColor And &HFF&)
Case rgbGreen
GetColorValue = (nColor And &HFF00&) / &H100
Case rgbBlue
GetColorValue = (nColor And &HFF0000) / &H10000
Case Else
Err.Raise vbObjectError + 512, "GetColorValue", "Incorrect color for return value"
End Select
End Function
Now to get, for example, the value of red at the position 1, 1 in a picturebox named Picture1 you'll use code simular to this:
VB Code:
MsgBox GetColorValue(Picture1.Point(1, 1), rgbRed)
Best regards
-
Nov 6th, 2001, 08:30 AM
#7
It's not a function. It's just 3 calculations, that's it.
So how about this then.
VB Code:
Dim lngPointColor as long
lngPointColor = Me.PictureBox1.Point(X_Coor, Y_Coor)
Debug.print "Amount of Red in Coordinate: " & (lngPointColor And &HFF&)
Debug.print "Amount of Green in Coordinate: " & (lngPointColor And &HFF00&) / &H100
Debug.print "Amount of Blue in Coordinate: " & (lngPointColor And &HFF0000) / &H10000
-
Nov 6th, 2001, 09:06 AM
#8
Thread Starter
Addicted Member
thanks
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
|