|
-
Feb 11th, 2001, 02:23 AM
#1
Thread Starter
PowerPoster
How do I extract Red, Green and Blue values from the value that is returned by GetPixel
-
Feb 11th, 2001, 07:41 AM
#2
Frenzied Member
Code:
'red value
dim retval as long
retval = GetRValue(GetPixel(HDC,x,y))
'green & blue
GetBValue & GetGValue
-
Feb 11th, 2001, 08:35 AM
#3
Member
Sorry but GetRValue() if a VC++ function not a VB function
-
Feb 11th, 2001, 09:29 AM
#4
Member
' Test routine to substract color components
Private Sub Command1_Click()
Dim Red As Long, Green As Long, Blue As Long
Dim Color As Long
' Create a color to test the sub
Color = RGB(150, 175, 200)
' Extract color components
Red = Color And &HFF
Green = (Color \ 256) And &HFF
Blue = (Color \ 256 \ 256) And &HFF
' Show
MsgBox "Red=" & Red ' Must be 150
MsgBox "Green=" & Green ' Must be 175
MsgBox "Blue=" & Blue ' Must be 200
End Sub
-
Feb 11th, 2001, 10:52 AM
#5
Code:
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
lColor = GetPixel(Picture1.hdc, X, Y)
'Get Red, Green and Blue
lRed = lColor Mod &H100
lGreen = Int(lColor / &H100) Mod &H100
lBlue = Int(lColor / &H10000) Mod &H100
End Sub
-
Feb 11th, 2001, 11:33 AM
#6
Member
A regular VB form has Point(x,y) methode for setting/getting a pixel, You don't need the GetPixel() function from the API.
Note: the GetPixel() API function's default mapping mode is in pixels and de default VB mapping mode is Twips.
-
Feb 11th, 2001, 11:44 AM
#7
You forgot to mention how much slower Point and PSet are compared to GetPixel and SetPixel.
-
Feb 11th, 2001, 01:54 PM
#8
Member
Your right, SetPixel() if about 50% faster then PSet () and GetPixel is about 70% faster then Point()
-
Feb 11th, 2001, 06:01 PM
#9
Fanatic Member
SetPixelV is even faster than SetPixel because it does not return the color the pixel is set to.
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
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
|