Subject Re: getcolor
From Wayne <nospam@nospam.com>
Date Sun, 17 Dec 2017 14:33:26 -0500
Newsgroups dbase.programming

Posted this in Getting Started but thought I'd get your take on it in this thread.

I started using rgbtohex() in convert.cc in duflp.  Tho it has been around for awhile, the code seems very wrong.

Feed 0,94,138 (red,green,blue) values into it, and it returns hex 8A5E00.  It should return 005E8A.  

The error is that it is flipping rgb values.  The code gets the hex for red (cRed) then for green (cGreen) then blue (cBlue).  BUT it adds these 3 strings incorrectly cBlue+cGreen+cRed.  It should be cRed+cGreen+cBlue to get the final hex value.

Trouble is, this code has been used so long I keep thinking I missed something.  

Have you found this to be the case?

Thanks,
Wayne

Rick Miller Wrote:

> On 12/13/2017 3:28 PM, Steve wrote:
> > Outstanding...it works.
> >
> > Any chance you or anyone here has some code to convert hexcolor to RGB format.    Found some formulas online, but they are pretty complicated.
> >
> > I know dbase has a function HtoI() for hex to integer.  Looks like it is a matter of parsing out the hexcode and converting each hex component into a RGB result to get to x,x,x RGB format.
> >
> > Will try coming up with something, but be great if someone knows if it has been done already.
> >
> > I searched the duflp and could not find anything.
> >
> > Thanks again Tim,
> > Steve
> >
> > Tim Ward Wrote:
> >
> >> On 13/12/2017 18:53, Steve wrote:
> >>>    form.oColorD  =  new colorDlg()
> >>> cRGB =  "255, 215, 0"
> >>>    cHex = RGBToHex(cRGB) // from convert.cc in duflp
> >>> form.oColorD.hexColor := cHex
> >>>    form.oColorD.show() // this DID NOT start from cHex color
> >>>    cColor = form.oColorD.hexcolor // E1C4C4 this looks correct for the selected color
> >>>
> >>> Where did I go wrong?
> >>
> >> Hi Steve,
> >>
> >>         I think the output from the RGBToHex() function in convert.cc adds an
> >> "0x" to the start of the hex string so cRGB =  "255, 215, 0" would give
> >> "0x00D7FF" (which is the format required by dbase colornormal). The
> >> colourDlg.cc hexColor just needs the hex bit ie 00D7FF without the
> >> preceeding "0x".
> >>
> >> regards Tim
> >
>
> Hi,
>
> cRGB =  "255, 215, 0"
> ?  cRGB
>
> // convert cRGB to a dBase color.
> cHex  =  RGBToHex(cRGB)
>
> // create the color dialog.
> form.oColorD   =  new colorDlg()
>
> // the set method can initialize
> // a default color for the dialog.
> form.oColorD.set("color", cHex)
> // when the color, (cHex) in this case,
> // used is not a default
> // value of the dialog it will be
> // added in the custom color group
> // at position 16 when show() is used.
>
> // display dialog.
> form.oColorD.show()
>
> // to convert the dialog color
> // value back to an RGB string.
> cValu =  form.oColorD.hexColor
> cColor   =  []
> cColor   += htoi(cValu.substring(0, 2))
> cColor   += [,]
> cColor   += htoi(cValu.substring(2, 4))
> cColor   += [,]
> cColor   += htoi(cValu.substring(4, 6))
>
> ?  cColor
>
> Hope it helps,
> Rick Miller