Board index » cppbuilder » RGB to Greyscale.
Michael Kruglo
![]() CBuilder Developer |
Fri, 07 Feb 2003 03:00:00 GMT
|
Michael Kruglo
![]() CBuilder Developer |
Fri, 07 Feb 2003 03:00:00 GMT
RGB to Greyscale.
Hi!
I need to convert RGB colors to greyscale. How can I do that? Also any idea on how to make it also blue, red, green etc. -scale would be appreciated. I use BCC++ 5.5 (free commandline tools), so I do not have all thsese VCL, OWL and other nice stuff so plain API code would be the only helpful. Point me to the code, please, or post one. Thanks in advance. |
Sandino Flores Moren
![]() CBuilder Developer |
Fri, 07 Feb 2003 03:00:00 GMT
Re:RGB to Greyscale.Quote> I need to convert RGB colors to greyscale. If this don't is enough, tellme please; by exaple, maybe you require real #include <windows.h> BYTE GetIntensity(COLORREF color) { r= getRValue(color); /**retrieve red component*/ i= sqrt( r*r +g*g +b*b )/sqrt(3.0); /**compare this operation with to Quote} COLORREF color= GetPixel(dc,x,y); /** someone Device Context, someone position inside */ BYTE gray= GetIntensity(color); SetPixel(dc,gray,gray,gray); And, how you must think; the color pixel in x,y position is rempalced by another in gray scale. Regards. Tigrux. |
Michael Kruglo
![]() CBuilder Developer |
Sat, 08 Feb 2003 03:00:00 GMT
Re:RGB to Greyscale.Thanx. Sandino Flores Moreno <sflo...@fcfm.uanl.mx> wrote in message news:39a1b90c_2@dnews... Quote> > I need to convert RGB colors to greyscale. |
Giulia
![]() CBuilder Developer |
Sat, 08 Feb 2003 03:00:00 GMT
Re:RGB to Greyscale.On Mon, 21 Aug 2000 18:28:53 -0500, "Sandino Flores Moreno" Quote<sflo...@fcfm.uanl.mx> wrote: Quote> i= sqrt( r*r +g*g +b*b )/sqrt(3.0); /**compare this operation with to Hi, you have to use one of the follwing two formulas in order Y = 0.114 * Blue + 0.587 * Green + 0.299 * Red or Y = 0.072169 * Blue + 0.715160 * Green + 0.21267 * Red (second preferred) where Y is the luminance level. Then you have to rebuild TColor in this manner: TColor( (int)Y * (65536 + 256 + 1) ); Hope this helps. Ciao! Giuliano |
Michael Kruglo
![]() CBuilder Developer |
Sat, 08 Feb 2003 03:00:00 GMT
Re:RGB to Greyscale.QuoteGiuliano <gcardin...@remove.adhoc.net> wrote in message Quote> On Mon, 21 Aug 2000 18:28:53 -0500, "Sandino Flores Moreno" Quote
free command line tools (BCC 5.5), so I can't use this stuff. How would that look in plain Win32 API. - Hide quoted text - - Show quoted text - Quote
|
Giulia
![]() CBuilder Developer |
Sat, 08 Feb 2003 03:00:00 GMT
Re:RGB to Greyscale.On Tue, 22 Aug 2000 18:58:01 +0200, "Michael Kruglos" <mik...@inter.net.il> wrote: [snip] Quote>TColor? Is this from something like OWL or VCL? I don't have BCB, I've got Ok, I've intended that you working with VCL: Ignore TColor. Ciao! Giuliano |
Michael Kruglo
![]() CBuilder Developer |
Sat, 08 Feb 2003 03:00:00 GMT
Re:RGB to Greyscale.QuoteGiuliano <gcardin...@remove.adhoc.net> wrote in message Quote> On Tue, 22 Aug 2000 18:58:01 +0200, "Michael Kruglos" Quote> wrote: connected with TColor((int)Y* (65536+256+1)); ? This TColor thingy seems to get int, but RGBQUAD and RGBTRIPLE seem to have R, G, B, and one reserved (for RGBQUAD). I need red, green and blue values to use them and not only Y. Anyway thanks for helping. Quote
|
Earl F. Glyn
![]() CBuilder Developer |
Sat, 08 Feb 2003 03:00:00 GMT
Re:RGB to Greyscale.Quote"Michael Kruglos" <mik...@inter.net.il> wrote in message news:8nulhi$7f1@bornews.borland.com... are defined by RGB(i, i, i), where i = 0 .. 255. So even though you have 16,777,216 colors with 24-bit graphics, you only have 256 shades of gray. -- Earl F. Glynn E-mail: EarlGl...@att.net efg's Computer Lab: http://www.efg2.com/Lab |
Michael Kruglo
![]() CBuilder Developer |
Sun, 09 Feb 2003 03:00:00 GMT
Re:RGB to Greyscale.Now I see. Thanks. Earl F. Glynn <EarlGl...@att.net> wrote in message news:8numhr$7c4@bornews.borland.com... Quote> "Michael Kruglos" <mik...@inter.net.il> wrote in message Quote
|