• Status: Solved
• Priority: Medium
• Security: Public
• Views: 821

# color and &HF0000000

I thought we need 6 digits to represent a color....but i found it is 8 digits, like &HF0000000.
Can you tell me how it works, which digit for what color?
0
learn
• 4
• 4
1 Solution

Commented:
You get 8 digits because color is a LONG value. Only the bottom six are required and the leading two zero's are often omitted.

pel = Me.Point(X, Y)
B = (pel And &HFF0000) / 65536
g = (pel And &HFF00) / 256 Mod 256
r = pel And &HFF

0

Commented:
I think THIS is the information that you requested.

It looks like we have &H00 at the beginning and & at the end with the middle 6 digits representing the colors:
0000xx - Red
00xx00 - Green
xx0000 - Blue

So we have:
&H000000FF&  - Red
&H0000FF00&  - Green
&H00FF0000&  - Blue
0

Author Commented:
Hi
Looks very interesting:
pel = Me.Point(X, Y)
B = (pel And &HFF0000) / 65536
g = (pel And &HFF00) / 256 Mod 256
r = pel And &HFF
is pel a color? why we can do 'pel and &HFF0000?
0

Commented:
Wanted to get each color on the 0-255 range. Not much use in having the B range from 65536 to 16711680 in steps of 65536. Much easier to understand when all are 0-255 plus now you can do:

Me.PSet (x, y), RGB(r, g, b)

and have it work.

0

Author Commented:
Hi Experts:

I have just found a color from VB:
&H8000000F&
If only lower six digits are used, why they put "80" at the first two positoins?
0

Commented:
MSB is *sign* bit ... Where did you find this tidbit? I've never seen a color value like this.

Don't know how the color function works on an internal level. It may simply ignore the MS byte or it could use it as a signal to change color modes. This could indicate that the color requested is #15 in the 16 color EGA palette.
0

Author Commented:
In fact, I am using this color (&H8000000F& ) in my program and the color is the light gray, like the default back color of the form.

I want to use some very light colors but they must be solid...I have tried to use GBR() but not easy to found such color and that is why I copied the above color from VB.

Do you know how to make sure the color is solid from GBR() or from &H....&?
0

Commented:
How about a nice control to allow you to mix your own colors? You can diddle the RGB values until you have the color you want and it will show you what the RGB values are:

VERSION 5.00
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.2#0"; "COMCTL32.OCX"
Begin VB.Form Color
Caption         =   "Color Test"
ClientHeight    =   4665
ClientLeft      =   60
ClientTop       =   345
ClientWidth     =   7530
Icon            =   "colors.frx":0000
ScaleHeight     =   4665
ScaleWidth      =   7530
StartUpPosition =   3  'Windows Default
Begin VB.CommandButton Command1
Cancel          =   -1  'True
Caption         =   "Exit"
Height          =   615
Left            =   840
TabIndex        =   14
Top             =   3840
Width           =   5775
End
Begin VB.TextBox Text2
Height          =   375
Index           =   2
Left            =   6720
TabIndex        =   13
Text            =   "Text2"
ToolTipText     =   "Blue Setting"
Top             =   3000
Width           =   615
End
Begin VB.TextBox Text2
Height          =   375
Index           =   1
Left            =   6720
TabIndex        =   12
Text            =   "Text2"
ToolTipText     =   "Green Setting"
Top             =   2520
Width           =   615
End
Begin VB.TextBox Text2
Height          =   375
Index           =   0
Left            =   6720
TabIndex        =   11
Text            =   "Text2"
ToolTipText     =   "RED Setting"
Top             =   2040
Width           =   615
End
Begin VB.TextBox Text1
Alignment       =   2  'Center
Height          =   375
Left            =   5640
TabIndex        =   10
Text            =   "Text1"
ToolTipText     =   "Current Grey scale setting"
Top             =   1320
Width           =   975
End
Begin VB.PictureBox Picture2
Height          =   1815
Left            =   5640
ScaleHeight     =   1755
ScaleWidth      =   915
TabIndex        =   3
Top             =   1800
Width           =   975
End
Begin VB.PictureBox Picture1
Height          =   975
Left            =   5640
ScaleHeight     =   915
ScaleWidth      =   915
TabIndex        =   1
Top             =   240
Width           =   975
End
Begin ComctlLib.Slider Slider1
Height          =   495
Left            =   720
TabIndex        =   0
ToolTipText     =   "Adjust the grey scale level"
Top             =   480
Width           =   4575
_ExtentX        =   8070
_ExtentY        =   873
_Version        =   327682
Max             =   255
TickFrequency   =   5
End
Begin ComctlLib.Slider Slider2
Height          =   495
Index           =   0
Left            =   720
TabIndex        =   2
ToolTipText     =   "Adjust the amount of RED in the color mix"
Top             =   1920
Width           =   4575
_ExtentX        =   8070
_ExtentY        =   873
_Version        =   327682
Max             =   255
TickFrequency   =   5
End
Begin ComctlLib.Slider Slider2
Height          =   495
Index           =   1
Left            =   720
TabIndex        =   8
ToolTipText     =   "Adjust the amount of GREEN in the color mix"
Top             =   2520
Width           =   4575
_ExtentX        =   8070
_ExtentY        =   873
_Version        =   327682
Max             =   255
TickFrequency   =   5
End
Begin ComctlLib.Slider Slider2
Height          =   495
Index           =   2
Left            =   720
TabIndex        =   9
ToolTipText     =   "Adjust the amount of BLUE in the color mix"
Top             =   3120
Width           =   4575
_ExtentX        =   8070
_ExtentY        =   873
_Version        =   327682
Max             =   255
TickFrequency   =   5
End
Begin VB.Label Label4
Alignment       =   1  'Right Justify
Caption         =   "Blue"
Height          =   375
Left            =   120
TabIndex        =   7
Top             =   3240
Width           =   495
End
Begin VB.Label Label3
Alignment       =   1  'Right Justify
Caption         =   "Green"
Height          =   375
Left            =   120
TabIndex        =   6
Top             =   2640
Width           =   495
End
Begin VB.Label Label2
Alignment       =   1  'Right Justify
Caption         =   "Red"
Height          =   375
Left            =   120
TabIndex        =   5
Top             =   2040
Width           =   495
End
Begin VB.Label Label1
Alignment       =   2  'Center
Caption         =   "Grey Scale"
Height          =   255
Left            =   840
TabIndex        =   4
Top             =   120
Width           =   4575
End
End
Attribute VB_Name = "Color"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub Command1_Click()
Call die
End Sub

Text2(0).BackColor = vbRed
Text2(0).ForeColor = vbWhite
Text2(0).Text = "0"
Text2(1).BackColor = vbGreen
Text2(1).ForeColor = vbWhite
Text2(1).Text = "0"
Text2(2).BackColor = vbBlue
Text2(2).ForeColor = vbWhite
Text2(2).Text = "0"
Call set_grey
Call set_color
End Sub

Call die
End Sub

Private Sub Slider1_Change()
Call set_grey
End Sub

Private Sub Slider1_Scroll()
Call set_grey
End Sub

Private Sub Slider2_Change(Index As Integer)
Call set_color
End Sub

Public Sub set_grey()
grey = Slider1.Value
Picture1.BackColor = RGB(grey, grey, grey)
Picture1.Cls
Picture1.Refresh
Text1.Text = grey
End Sub
Public Sub set_color()
red = Slider2(0).Value
green = Slider2(1).Value
blue = Slider2(2).Value
Picture2.BackColor = RGB(red, green, blue)
Picture2.Cls
Picture2.Refresh
Text2(0).Text = red
Text2(1).Text = green
Text2(2).Text = blue
End Sub

Private Sub Slider2_Scroll(Index As Integer)
Call set_color
End Sub
Public Sub die()
Dim frm As Form
For Each frm In Forms
Next frm
End
End Sub

If this works - gimme da points!

M

0

Author Commented:
Hi mark2150:

I believe the code may help me.

However, I don't know how to make that work. I need to compile that or not?

Cheers.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.