Click here to Skip to main content
Click here to Skip to main content

Colorz - The RGB Assistant

By , 28 Aug 2006
 

Sample Image - Colorz

Description

After developing applications and web pages for a while, I came to a point where I realized a major gap exists in the typical programming paradigm in that visualizing fine-grained color values in code was almost impossible unless you happen to use a WYSIYYG or RAD environment. And that there are still plenty of circumstances where such an environment will still be used.

Even the notion of HTML's naming colors never really helped because it only applied to basic values (i.e., <body bgcolor="white">), or had some obscure name that nobody even knows what it is. Lastly, most developers already know the basic colors, like RGB 255, 255, 255 equals white, RGB 0, 255, 255 equals cyan, etc.

This still begs the question, what if you want to see a color, perhaps coordinate a color in an environment-independent manner that was quick to use and allowed for easy copy and pasting for a pseudo integration mechanism. And, regardless of my editor of choice I would always have a means to do this. Thus, Colorz was born.

What Colorz is, is a tiny program that allows you to use three scrollbars to specify colors in the RGB color space by manipulating the R intensity, the G intensity, and the B intensity of a color while showing you what it looks like and the appropriate values, essentially allowing you to see a color in real-time while you choose it.

Although Colorz was one of the first applications of such a nature out there on the web, realistically, the idea for it is not exclusive to me. As such, my goal was to focus in on just what it is Colorz is supposed to be. With this in mind, the idea was to keep it small and lightweight to deliver just what's needed and nothing more. It has a smaller memory footprint than Notepad so it will not hog system resources.

Specifications

  • Mode

    Switch between foreground (text color) and background modes. This enables you to coordinate color values and visually see what color looks good with what color.

  • Format
    1. Decimal -- This option allows you to specify the RGB color in decimal notation, with values between 0 and 255 for each intensity (suitable for environments such as the Windows API).
    2. Float -- This option allows you to specify the RGB color in floating point notation, with values between 0.0 and 1.0 for each intensity (suitable for environments such as OpenGL).
    3. Hex -- This option allows you to specify the RGB color in hexadecimal notation, with values between 0 and FF for each intensity (suitable for environments such as HTML).
  • Options

    1. Grayscale -- This option keeps the scrollbars in uniform to allow only shades of gray.
    2. On Top -- This option will keep the Colorz window on top of other windows for convenient placement while you are working.
    3. Grab Color -- This option is probably the reason most people use this application. It will allow you to pick the RGB color off of any point on the screen using the cursor. This can be a huge timesaver if you find the perfect color and want to know the values for it. After turning this option on, hold down the CTRL key to activate it.
    4. Auto Copy -- This feature allows you to paste the value directly in your code! Turning this on will have whatever value you specify (or pulled from the screen) be automatically copied to the clipboard.
  • Features
    • Has a small memory footprint, and will not hog system resources.
    • Highlights the textual output in correspondence to the Auto Copy selection.
    • Allows you to use thee different ways to specify a color; so regardless of the environment, Colorz will work with it.
  • Fixes
    • The "Grab Color" activation hotkey was changed to CTRL to avoid conflicts with menus and accelerators.
    • Now, when switching between background and foreground mode, Colorz retains the separate values.
    • When finished grabbing a color, the scrollbars automatically reflect the new color.
    • Must hold down the ALT key for the "Grab Color" feature to work.

      This fixes you picking your color and losing the information when you move the cursor again.

This program has made my life a little easier numerous times. If it helps me, I hope it'll help someone else out there in cyberspace. And maybe, some will learn from it. Enjoy!

Technical

This program demonstrates what is involved in writing a dialog-based application for Windows® using nothing but C and the Windows API. It further explores concepts pertaining to the GDI, with a focus on device contexts and bit block transfers. And, it shows how to manipulate the clipboard.

There was a workaround needed for the "Grab Color" feature. The reason being is that I used the GetPixel function for it; therefore, if you have coordinates for a non-client area in a window, it returns -1. This is not a valid color, so I used BitBlt to rectify the problem by copying the pixel to a static control and then using GetPixel on the control, thus returning a valid color. The following code demonstrates this technique.

// get a handle to the window under the cursor
hWndxy = WindowFromPoint(spoint);

// get a handle to the preview pane
hPreview = GetDlgItem(hWnd,IDC_STATIC_PREVIEW);

// get the dc for the window in question
hDC = GetDC(hWndxy);

// GetPixel() requires client coordinates
ScreenToClient(hWndxy, &cursor);
rgb = GetPixel(hDC, cursor.x, cursor.y);

/*/
/ / The following is a workaround for the GetPixel API. If the
/ / cursor is over a titlebar or other non-client areas of the
/ / window it'll return -1 for the RGB intensities. In this case
/ / we use BitBlt to copy the color to our control and extract
/ / the the intensities from that.
/*/

// check to see if intensities are valid
if(rgb == -1)
{
    HDC hDCPrev = GetDC(hPreview);

    BitBlt(hDCPrev, 0, 0, 1, 1, hDC, 
           cursor.x, cursor.y, SRCCOPY);
    rgb = GetPixel(hDCPrev, 0, 0);

    // clean up
    ReleaseDC(hPreview, hDCPrev);
}

// clean up
ReleaseDC(hWndxy, hDC);

Credits

This program uses a function called MoveWnd to center the window when the program starts. This function originated as CenterWindow, and was found in an excellent book named "Win32 Programming" by Brent E. Rector and Joseph M. Newcomer. I rewrote the function to fix a couple of things, add extra functionality, and I renamed it in the process.

I wrote the remains of the program from scratch with the assistance of the ever popular MSDN Library and knowledge acquired from "Win32 Programming".

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Jeremy Falcon
Software Developer (Senior)
United States United States
I've been in software development since 1994. Over the years I've learned quite a lot in what it takes to complete the process of pushing out a quality product to customers in a timely fashion. As most of my colleagues could attest, there have been many challenges in our new and growing field in the past couple of decades as the industry matures rapidly. Much more so than most others historically speaking.
 
As such, I've learned one of the best aspects of software engineering is embracing the change that inherently comes along with it as new technologies constantly emerge to help us improve our world one application at a time as we make sense of the overwhelming amount of data now prevalent in the Information Age.
 
We truly live in a time unlike that ever known to mankind in recorded history, and it is my hope to do my part to help it along to face the challenges and demands of tomorrow.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralStill the bestmemberMike Gaskey3-Apr-08 3:49 
Just downloaded on my Vista home premium system, works like a champ.
 
Mike - typical white guy
 
Thomas Mann - "Tolerance becomes a crime when applied to evil."
 
The NYT - my leftist brochure.
 
Calling an illegal alien an “undocumented immigrant” is like calling a drug dealer an “unlicensed pharmacist”.

God doesn't believe in atheists, therefore they don't exist.

GeneralRe: Still the bestmemberJeremy Falcon6-Apr-08 11:21 
Mike Gaskey wrote:
Still the best

 
Thanks man. That means a lot.
 
Mike Gaskey wrote:
works like a champ

 
I still haven't taken the Vista plunge, so that's good to know. Thanks.
 
Jeremy Falcon
Oatmeal Engine[^]

Generallatest versionmemberrenjith_sr20-May-07 1:45 
dude, has 2.0 been released yet?
 

 

 
colorz: ...a step ahead, inventive ideas, exceptional designs
GeneralRe: latest versionmemberJeremy Falcon9-Apr-08 7:08 
renjith_sr wrote:
dude, has 2.0 been released yet?

 
2.0 was scrapped, but I think I'll be making version 1.4 soon to add 64-bit support and a few goodies like a magnifying lens, etc.
 
Jeremy Falcon
Oatmeal Engine[^]

GeneralWindows XPmemberequivocator9923-Nov-06 4:40 
Is it supposed to work on Windows XP because I'm receiving this error when I try to run it.
 
"This applications has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem."
 
And don't ask if I reinstalled. Big Grin | :-D
 
BTW, Thanks for the reference. Cool | :cool:
GeneralRe: Windows XPmemberJeremy Falcon23-Nov-06 11:48 
equivocator99 wrote:
"This applications has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem."

 
It has to do with the manifest file. I think MS may have changed some requirements for it. It works on some people's machines and worked on mine in the past until recently (zero changes on my part). I do have Windows Update, so that may come into consideration.
 
Nevertheless, I'll dig deeper into the issue, but in the meantime you can compile the source in something besides VS2005 or just drop the extra manifest file data from the project options to get it to run.
 

GeneralFeaturememberS Douglas14-Nov-06 22:01 

Seeing how you’re actively working on this app, why not add a Color picker to it, be great if it offered a simple CColorDialog to choose the color and let me specify the output, say hex, decimal or name.

 


I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:


GeneralRe: FeaturememberJeremy Falcon15-Nov-06 6:52 
S Douglas wrote:
be great if it offered a simple CColorDialog to choose the color and let me specify the output, say hex, decimal or name.

 
A standard color dialog allows you to specify RGB values to choose a color or choose from presets, how is this much different than what's already there?
 
Or is this a way of saying you prefer the way that dialog looks when choosing a color? Big Grin | :-D
 

GeneralRe: FeaturememberS Douglas18-Nov-06 21:08 
Jeremy Falcon wrote:
Or is this a way of saying you prefer the way that dialog looks when choosing a color?

:->
For just quickly picking a given color using the scroll bars is a bit much. Now refining that color with the scroll bars isn’t so bad but getting the approximate color is a bit much.
 


I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:


GeneralRe: FeaturememberJeremy Falcon23-Nov-06 13:14 
S Douglas wrote:
but getting the approximate color is a bit much.

 
The idea behind colors was simplicity and being small. With my usage of it I found out that you tend to learn what hues match which scrollbar positions just by using it a few times. Say, for instance the first time you specify orange you know what to do to specify it again.
 

NewsColorz 1.3.1 DemystifiedmemberJeremy Falcon25-Aug-06 19:00 
Ok, 2.0 never did make it. The reason being is the stuff I wanted to add (ICC profiles, etc.) was just loosing sight of what Colorz was really meant to be - which is extremely lightweight and versatile.
 
Rather than make room for specifying colors in 20 different color spaces that will probably never get used anyway and ICC profiles that take time to configure, I thought it would be best to stick with one space (RGB) and continue to add ways to work with the colors in that particular space to keep Colorz quick and snappy.
 
Things like color management and color space conversions just seem to not fit the small footprint, sit in the wee corner of your screen kinda app I intended Colorz to be. As such, 2.0 has been canned.
 
So, this release is more of a incremental one, adding support for floating point representation (a format that many scientific applications expect to receive RGB colors in) along with some code clean ups so I won't have to hang my head in shame if someone actually sees it. Smile | :)
 
Jeremy Falcon
 
The mind is like a parachute. It works best when it is open. - Colin Angus Mackay (2006-08-18)

GeneralRe: Colorz 1.3.1 DemystifiedmemberMike Gaskey29-Aug-06 1:37 
Jeremy Falcon wrote:
which is extremely lightweight and versatile

 
and probably one of the very best tool kit items around.
 
Mike
Dear NYT - the fact is, the founding fathers hung traitors.
Vincent Reynolds: My opposition is as enlightened as your support, jackass.
dennisd45: My view of the world is slightly more nuanced
dennisd45 (the NAMBLA supporter) wrote: I know exactly what it means. So shut up you mother killing baby raper.
 

GeneralRe: Colorz 1.3.1 DemystifiedmemberJeremy Falcon29-Aug-06 4:54 
Thank you. I am humbled. Blush | :O
 
It's not accidental though that I updated it to support floats and I, ahem, recently got into OpenGL. Laugh | :laugh: I could use the decimal format in OGL, but it just converts it anyway behind the scenes so I figured I'd save the unneeded processing.
 

GeneralExcellentmemberGareth Haslip22-Sep-04 2:33 
I'm partially color blind, so this little app is a god send to me! Especially the color grabber, so I can find out what precise color things are!!!
 
Nice one.
GeneralRe: ExcellentmemberJeremy Falcon22-Sep-04 4:58 
Thank you.
 
One of these days I'll get around to writing a newer version. I was originally thinking of having a bunch of different color space conversions, but found that to be impractical. If you don't mind, I'd be grateful if you could let me know (over time) what you find useful and if anything what you'd like to have in a newer version.
 
One of the things I intend to do for 2.0 is have the area around the cursor magnified (if chosen) to make it easier to see each pixel you're grabbing.
 
Jeremy Falcon
General2.0 means 2 years...memberinternal27-Oct-04 20:12 
Poke tongue | ;-P
Smart tool! But still too far for 2.0?
What I dream about it is when I have to choose some blue text to fit gray background could you give me the exact blue automatically? I've done it now by one-one-checkFrown | :(
 
Sing when we're programming.
GeneralRe: 2.0 means 2 years...memberJeremy Falcon28-Oct-04 5:10 
Blush | :O
 
I started on 2.0 a while back but dropped it because I was putting too much crap into it (like color space conversion, ICC profiles, etc.). I then realized I was loosing sight of the original goal with Colorz -- to make it very lightweight (in regards to memory consumption) and to help with color values. The typical developer just doesn't need the stuff I was putting in.
 
But, your idea is awesome (if we're on the same page)! Are you suggesting to have Colorz automatically coordinate colors? Say, if you choose gray, it'll show you all the blues that go with it if you want a blue color for text? If so, that may be just enough reason to have a 2.0. And, of course, I'd give you credit for the idea.
 
BTW, at first I mistook your post and thought you were asking for the color values. Well, here's what I came up with in case you want 'em anyway.
 
Foreground: #5FE1FF
Background: #7B7B7B
 
Jeremy Falcon
GeneralRe: 2.0 means 2 years...memberinternal29-Oct-04 3:02 
Jeremy Falcon wrote:
I started on 2.0 a while back but dropped it because I was putting too much crap into it
 
Yeah, I understand to know what to do is more important than to know how to do it sometimes.
 
As a programmer I think why Colorz is useful for us is that programmer is not artist but GUI is always important. If there is no designer assisting we have to grab it from successful software, and if we want to do some innovation... For me I really don't know it before I've seen itSigh | :sigh: Color Blind~~~
 
Sing when we're programming.
QuestionRefresh ?memberKim Marius Haugen24-Feb-04 10:01 
I have this to paint the decive:
 
WM_PAINT:
{
hDC = BeginPaint(hColor, &Ps);
 
NewBrush = CreateSolidBrush(RGB(200, 100, 50));
 
SelectObject(hDC, NewBrush);
 
Rectangle(hDC, 20, 20, 100, 100);
 
DeleteObject(NewBrush);
EndPaint(hColor, &ps);
}
break;
 
But how can i "update" the device when i scroll my scrollbar (making a color picker) to show the new color specified ?
 
Would apreciate all comments Smile | :)

AnswerRe: Refresh ?memberJeremy Falcon24-Feb-04 13:52 
You have to force a repaint for it to take effect. In Colorz I used the InvalidateRgn API call to do this.
 
BTW, why make a color picker when you can just use something like Colorz already?
 
Jeremy Falcon
GeneralRefresh ?memberKim Marius Haugen26-Feb-04 9:25 
Yeah, found it out and used InvalidateRect.
Well, I want to learn as much I can, and I can't just copy&paste then, but thanks anyway. Your answear is most appreciatet. Learn alot from your code thoug.Smile | :)
GeneralRe: Refresh ?memberJeremy Falcon26-Feb-04 9:30 
Kim Marius Haugen wrote:
Well, I want to learn as much I can, and I can't just copy&paste then, but thanks anyway.
 
I can understand that! Smile | :)
 
Jeremy Falcon
GeneralColorz 2.0memberJeremy Falcon13-May-02 10:37 
Will be out very soon! I've been sporadically working on it whilst ever so delightfully procrastinating at times. But, it's getting closer. If you don't see it in about a month, please kick somebody else's butt. Smile | :)
 
Jeremy L. Falcon
"It's in the mail."

Homepage : Sonork = 100.16311
Surely some striving souls survive symptomatic stress?

GeneralRe: Colorz 2.0sussGeert Delmeiren16-Jul-02 1:08 
Hi Jeremy,
 
We're two months further now.
Any idea when we can expect v2.0?
What are the new features?
GeneralRe: Colorz 2.0memberJeremy Falcon18-Jul-02 16:59 
Thanks for your interest!
 
Geert Delmeiren wrote:
We're two months further now.
 
Yes we are. Blush | :O
 
Geert Delmeiren wrote:
Any idea when we can expect v2.0?
 
Soon - like in a week or two. Unsure | :~
 
Geert Delmeiren wrote:
What are the new features?
 
It'll work with more than one color space, support ICC profiles for the device-dependent color spaces (CMYK, CMY), enhanced grab color feature, more compact window and more manageable, windows/mac compatibility, cleaned up the code, and so forth. Oh yeah, I added an about box also. It uses a bit more memory this time around, but it's still close to notepad.
 
Jeremy Falcon
Imputek
 
"..." - Paul Watson  07-17
GeneralRe: Colorz 2.0sussGeert Delmeiren18-Jul-02 20:25 
Jeremy Falcon wrote:
Soon - like in a week or two.
 
I nearly can't wait. Wink | ;)
 
Jeremy Falcon wrote:
It'll work with more than one color space, support ICC profiles for the device-dependent color spaces (CMYK, CMY), enhanced grab color feature, more compact window and more manageable, windows/mac compatibility, cleaned up the code, and so forth. Oh yeah, I added an about box also.
 
Sounds good. Although I was already very satisfied with your first version (gave it a big 5).

GeneralRe: Colorz 2.0memberJeremy Falcon19-Jul-02 8:18 
Geert Delmeiren wrote:
gave it a big 5
 
Heck, I would've been happy with a small 5. Smile | :) Thanks!
 
Jeremy Falcon
Imputek
 
"..." - Paul Watson  07-17
GeneralRe: Colorz 2.0memberJörgen Sigvardsson10-Feb-04 7:23 
Dude? Where's 2.0? Wink | ;)
 
--
Gott weiß ich will kein Engel sein.
GeneralRe: Colorz 2.0memberJeremy Falcon10-Feb-04 8:48 
Well, did start doing some work on it, but I decided it would be best to make it integrate with VS.NET using the VSIP instead of being a standalone app. The catch is I'm not familiar with the .NET IDE yet, so I have some learning to do first.
 
Jeremy Falcon
GeneralGrab color no longer worksmemberMatt Philmon13-Nov-00 3:17 
Grab color is no longer working for me. I'm running Windows NT 4.0 (Service Pack 6a) with IE 5.5 (SP1).
GeneralRe: Grab color no longer worksmemberJeremy Falcon13-Nov-00 5:46 
You have to hold down the ALT key for it to work. This fixes the problem of you picking a color with the cursor and having Colorz pick up a new color when you move the cursor again. Now you can let go of ALT, so you do not need to worry about the mouse move.
 
BTW, there will be another update to codeproject. Currently, (the Nov. 10 update) has a little bug that sends garbage to the clipboard for the Auto Copy. This has been fixed, so it's a matter waiting for the post to go online.
 
Just make sure you end up with a version that was updated after Nov. 10 please.

QuestionGrab Color option in Colorz : how do I turn it off?sussRudi Farkas11-Sep-00 1:06 
Nice utility.
Did I miss something obvious: How do I turn off the grabbing when I positioned the cursor
over the desired color in some other window?
I expected that LMOUSEDOWN would do it but it does not.
 
Rud
AnswerRe: Grab Color option in Colorz : how do I turn it off?sussJeremy Falcon15-Sep-00 17:12 
I realized that too, but thanks for pointing it out. I'm making a newer version which implements a feature like so.
 
Sorry for the inconvenience, it's just been that work, moving, and what-nots have been driving me crazy lately
GeneralWeb Safe PalettesussMax Zakharzhevskiy15-Feb-00 12:11 
If you would like to have Web Safe Tool it will be better to use step 0x33 for R G B components. For instance, valid values for R channel will be 0x00, 0x33, 0x66, 0x99, 0xCC and 0xFF. I hope it will help
GeneralBad linksussEddie Velasquez15-Feb-00 2:34 
The source link is broken

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130617.1 | Last Updated 28 Aug 2006
Article Copyright 2000 by Jeremy Falcon
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid