Rich Text Format: Documents Background Color

  1. ‹ Older
  2. 5 weeks ago

    Jean-Yves P

    Feb 17 Pre-Release Testers, Xojo Pro Europe (France, Besançon)

    1261823 in hex is &h1340FF
    aren't they the R G and B values on 8 bits ?

  3. Martin T

    Feb 17 Pre-Release Testers Germany

    Unfortunately, it's not that simple. The background color in the test document is set to red. You can download the RTF here. If I enter your value into a color converter, I get a blue tone.

  4. Jean-Yves P

    Feb 17 Pre-Release Testers, Xojo Pro Europe (France, Besançon)

    &hFF4013 gives you a beautiful red.
    may be you could give us some samples: this number gives this color, so that we can search ?

  5. Dave S

    Feb 17 San Diego, California USA

    well it is

    change it to 0 and you get black
    change it to 65535 you get yellow
    65280 (00FF00) is green
    16777215 is white (FFFFFF)

    but it is NOT RGB... seems it is BGR because 16711680 (FF0000) returns BLUE

  6. Beatrix W

    Feb 17 Pre-Release Testers Europe (Germany)

    I remember from VBA times that Office uses a long for RGB. For instance mentioned here: https://stackoverflow.com/questions/25201173/vba-store-rgb-colour-in-variable . You may have to Goggle for the exact formula.

  7. Beatrix W

    Feb 17 Pre-Release Testers Europe (Germany)

    Got it: http://www.vbforums.com/showthread.php?186884-Convert-an-RGB-value-to-a-long-or-a-long-to-RGB

  8. Martin T

    Feb 17 Pre-Release Testers Germany

    @Dave S Thanks. How did you convert the color?

  9. Dave S

    Feb 17 San Diego, California USA

    @MartinTrippensee @Dave S Thanks. How did you convert the color?

    what do you mean how did I convert the color?
    I entered values for colors that I knew, and observed the results. when I entered 16711680 I expected RED but got BLUE therefore the Red and Blue bytes are transposed..... once I determined that all other values resulted in the expected color

    Blue*0xFF0000 + Green*0x00FF00 + Red

  10. Martin T

    Feb 17 Pre-Release Testers Germany

    Forget my question, I have now understood how you came to the respective values. Thank you very much, that is the solution to the riddle.

  11. Martin T

    Feb 17 Pre-Release Testers Germany

    Sorry, ones again: I understand how to convert this binary value using Hex function to readable color code. What does the calculation of a color given in Xojo look like in this binary format?

  12. Dave S

    Feb 17 San Diego, California USA

    for the most part a color is a 24 bit number... a number is a number as far as the computer is concerned. the digits 0-9, and hex representation of for the convience of people

    12345678 is 0xBC614E in HEX and 101111000110000101001110 in Binary

    Xojo uses RGB where R=Red as a value between 0-255 [0x00 to 0xFF], G=Green, and B=Blue (seems RTF flips Red and Blue)

    Xojo RED would be RGB(255,0,0) or &CFF0000

    not sure if any of that answers you question

  13. Martin T

    Feb 17 Pre-Release Testers Germany

    Suppose I have this color (purple):

    Dim c As Color = &c470bb7 ' -> {\sp{\sn fillColor}{\sv ???}}

    How do I calculate the numeric value and then write it to an RTF file as above (???)?

  14. Dave S

    Feb 17 San Diego, California USA
    Edited 5 weeks ago

    @MartinTrippensee Suppose I have this color (purple):

    Dim c As Color = &c470bb7 ' -> {\sp{\sn fillColor}{\sv ???}}

    How do I calculate the numeric value and then write it to an RTF file as above (???)?

    (&H47 * 65536) + (&0B * 256) + (&b7)

    (71 * 65536 ) + (11 * 256 ) + ( 183)
    (4653056) + ( 2816) + (183) = 4656055

    Simple Hex to Decimal conversion

    OR

    dim x as Integer = &H470bb7 // use H not C
    msgbox str(x)
  15. Ulrich B

    Feb 17 Pre-Release Testers, Xojo Pro Europe (Germany, Berlin) · xo...

    In other words

    Public Function toBGRInteger(extends c as color) as Integer
      return c.Red+c.Green*256+c.Blue*65536
    End Function
  16. Martin T

    Feb 17 Pre-Release Testers Germany

    OK, i made some test. Using the following code and enter the returned rtfColorCode into the RTF, returns not the same Color in Microsoft Word. Looks like there are small differences in calculation:

    Dim c As Color = &c470bb7
    
    Dim r As Integer = c.Red * 65536
    Dim g As Integer = c.Green * 256
    Dim b As Integer = c.Blue
    
    Rim rtfColorCode As Integer = r + g + b ' Result: 4656055, open it with Word returns &cB70B47
  17. Ulrich B

    Feb 17 Pre-Release Testers, Xojo Pro Europe (Germany, Berlin) · xo...

    You mixed up red and blue values. The Integer result for &c470bb7 is 11995975.

  18. Dave S

    Feb 17 San Diego, California USA

    @Ulrich B You mixed up red and blue values. The Integer result for &c470bb7 is 11995975.

    actually 0x470bb7 is 4656055, but what he really wants is 0xb70b47 which is 11995975

    like you said he neglected to transpose the Red and Blue bytes.... Xojo (and the rest of the world) is R-G-B
    but seems Word is B-G-R

    so the function you posted will transform an Xojo Color to a Word Color

  19. Martin T

    Feb 18 Pre-Release Testers Germany

    Thanks David and Ulrich. I can live with the small difference between the color Xojo returns and the color generated by Word from the given Xojo Integer.

  20. Dave S

    Feb 18 San Diego, California USA

    @MartinTrippensee he small difference between the color Xojo returns and the color generated by Word

    difference... what difference?

    The only differnce is that Word swaps the Red and Blue bytes.. .otherwise they should render the exact same colors (unless Word uses a non-standard colorspace)

  21. Martin T

    Feb 18 Pre-Release Testers Germany

    Sorry Dave, there was a typo in my code. Everything works fine with Ulrich's function. Thank you all for your help.

or Sign Up to reply!