Link to home
Start Free TrialLog in
Avatar of Julian_K
Julian_KFlag for Bulgaria

asked on

Problem with RGB

Hi, Experts.

Here is my Problem... to understand me better, furst put this code on a Command1_Click event:

Private Sub Command1_Click()
    Me.Line (0, 0)-(1000, 1000), &HFF0000, BF
    Me.Line (1000, 0)-(2000, 1000), &HFF2020, BF
    Me.Line (0, 1000)-(1000, 2000), &HBF0000, BF
End Sub

Here, as you see, I paint 3 boxes.
First is blue,
second is blue, but lighter,
third is blue, darker.

If You calculate the sum of RGB for the lighter and the darker, their absolute values of (difference from the blue) are equal . But... it does not seem so to my eyes.

The problem is, that the lighter does not seem to be as bright, as the darker is dark. :-(

Let's say I'm trying to draw 3d borders around a box.

So, do you have any idea how can I "Shift" some color in both directions (ligter, darker), so the visual perception is ok?

Or is it that just my display is not ok? :-)))
Avatar of nichia
nichia

The reason that the light blue is not as "bright" is that you have desaturated it by adding red and green.  The other colors have no R-G component, and so look more saturated.

Instead of trying to do this by the numbers, I suggest picking your colors from the color picker (by eye), then coding in the values based on what *looks* right to you.

Hope it helps!
Avatar of Julian_K

ASKER

Hello, nichia.
I need EXACTLY "by the numbers" as you say. That's because the color may change. So I need to change the brighter and the darker border accordingly to it.
Avatar of Richie_Simonetti
That's not a bad idea! You could do it with mspaint also.
what nichia saids is:
Use color picker to know which are the long values for that colors and write them down in the code.
You could use the picker from the form itself.
Richie, are you kidding or what?
The question is serious. I need this colors to be calculated. I have tried it with different algorythms, and they seem to work fine on some colors which are mixture of RGB, but can not handle with some other colors. I'm DESPERATE. HELP :-(
Convert from HSL to RGB
http://abstractvb.com/code.asp?F=50&P=1&A=926

Convert from RGB to HSL
http://abstractvb.com/code.asp?F=50&P=1&A=927

What you need to do is convert your RGB color to HSL (Hue, Saturation and Luminance) then change the luminance value to make it brighter or darker and convert back to RGB to display that color.
Is it what you want?
   Me.Line (0, 0)-(1000, 1000), RGB(0, 0, 255), BF
   Me.Line (1000, 0)-(2000, 1000), RGB(0, 0, 225), BF
   Me.Line (0, 1000)-(1000, 2000), RGB(0, 0, 150), BF
The color model makes no difference in this case: the only way to lighten a pure color is to reduce its saturation and the only way to darken it is to bring down the brightness (lightness).  This is exactly what you did and did not like the results.

ASKER CERTIFIED SOLUTION
Avatar of rspahitz
rspahitz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
First, I want to thank to all of You.

ashunigam, I will reject your answer. Please read more carefully before answering...

nichia, you're correct, and I thank You, but this is all in theory. I need some example code.


PaulHews, thanks for the links. The functions that You provided, return more correct values, than mine.


Yet, here stays the "Human Perception" factor, as rspahitz said, and that cuts my brain. :-(

So, the 150 points will go to PaulHews, he deserves them.

(PaulHews, I'll open another empty question for you to get your points.)


rspahitz, You got my question :-)
As for the so-called "Human Factor", You, (or anyone else) If You come with some idea, that is more defined, I will award You double (300pts), because THIS IS the problem, I had in mind, while writing the question.

I'm just not sure if this problem could be solved so easily...
ashunigam, as I said, I'm rejecting your answer. I'm Sorry, but what you provide as an answer is far away from the problem.
As I said, I increase the value of this question to 300 pts., but now the topic is how to avoid that "Human Factor".
I'd say that the best way to evaluate the "human factor" is to start by observing a specific color in the color bar.

To do this, pick any VB form's forecolor (or any other color property.)  In the dropdown list select the palette and right-click on one of the boxes at the bottom.  This opens a "Define Color" window (similar to the color-picker in Windows.)

Zero-out the Red and Green components and notice where the arrow appears next to the vertical brightness bar (just above the RGB color values.)  It right in the middle.  Anything below this is a darker shde of blue.  Anything above this is a brighter shade of red and green.  (Drag the arrow to observe this effect.)

I think this is the approach you need to use.
Hi Julian_K,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Split points between: PaulHews and rspahitz

Julian_K, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
Hi, DanRollins.

1. I awarded PaulHews, opening a special question for him (with topic "Points for PaulHews") and he got his points.
This is because he gave me some extra information I was not asking for, but I found it valuable.
============================
2. My Question was: "...So, do you have any idea how can I "Shift" some color in both directions (ligter, darker), so the visual perception is ok?"
============================
I do not think anybody answered my question (at least with some usefull code or function or any other kind of exact algorythm for calculation).

3. If someone MUST have the points, I prefer giving them to rspahitz

Thank you.
Julian
Thanks for returning to help clean up this old question.

If you want to award points to rspahitz, click the [Accept comment as answer] link near his comment.

If you don't want to award any points, say so and a Moderator will handle it in about 7 days (to be honest, I think these experts deserve some credit!  PaulHews comment was brilliant, and rspahitz did provide help with your SECOND question).

-- Dan