Solved

Easy answer!

Posted on 1998-08-03
7
195 Views
Last Modified: 2010-08-05
I'm working on a DLL in VC 5 for use by VB 5.  The dll uses the hDC content to change the graphics on a form.  What I need to do is calculate the individual RGB values of a point.  I'm reading the point using GETPIXEL, and setting it using SETPIXEL.  Anyone know how I could calculate the RGB values of a point quickly and easily?
0
Comment
Question by:codewizard
  • 5
  • 2
7 Comments
 
LVL 6

Accepted Solution

by:
thresher_shark earned 20 total points
Comment Utility
Try the following:
void CalcRGB (char &r, char &g, char &b, char rgb)
{ r = (char) rgb;
  b = (char) >> 8;
  g = (char) >> 16;
}
0
 
LVL 6

Expert Comment

by:thresher_shark
Comment Utility
Sheesh, I just realized that I didn't write the function
correctly.  Use the following, and disregard my original answer:

void CalcRGB (BYTE &r, BYTE &g, BYTE &b, COLORREF rgb)
{ r = (BYTE) rgb;
  g = (BYTE) (rgb >> 8);
  b = (BYTE) (rgb >> 16);
}

Don't you love it when you're in a hurry?

You supply the function three variables.  The first three
variables are the ones you want the individual red, green,
and blue intensities to be stored.  The last variable is
the value that you get from the GetPixel function.  The
function prototype looks like the following:

void CalcRGB (BYTE &, BYTE &, BYTE &, COLORREF);

If you have any questions, feel free to ask.
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
To be on the safe side you might want to use the macros defined by windows for this.  They are
GetRValue(), GetGValue() and GetBValue().  Should yield the same results, but it is usually safest to use the windows provided stuff in case they change things.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 6

Expert Comment

by:thresher_shark
Comment Utility
You know, when I saw the question, I thought there should be a Windows provided solution, but at the time I couldn't think of it so I improvised :-)

codewizard, if you want to calculate all the variables at once and stick with the Windows functions that nietod mentioned use the following instead:

void CalcRGB (BYTE &r, BYTE &g, BYTE &b, COLORREF rgb)
{ r = GetRValue (rgb);
  g = GetGValue (rgb);
  b = GetBValue (rgb);
}
0
 
LVL 6

Expert Comment

by:thresher_shark
Comment Utility
You know, when I saw the question, I thought there should be a Windows provided solution, but at the time I couldn't think of it so I improvised :-)

codewizard, if you want to calculate all the variables at once and stick with the Windows functions that nietod mentioned use the following instead:

void CalcRGB (BYTE &r, BYTE &g, BYTE &b, COLORREF rgb)
{ r = GetRValue (rgb);
  g = GetGValue (rgb);
  b = GetBValue (rgb);
}
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
Then you might not be aware that there is a reverse macro RGB() that creates a COLORREF from three color values.
0
 
LVL 6

Expert Comment

by:thresher_shark
Comment Utility
Actually I was aware of that one.  Thanks for checking though.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now