none
ARGB Different Value ? RRS feed

  • Question

  • Greetings,

    I'm looking at this file in WCell project on Github, I've discovered it has it own color type values and I'm confused about it.
    So.. could someone please explain to me what type of color value is this correctly ?,
    and how do I normally convert a rgb value (255, 255, 255) to this type of a color value?

    Thanks in advance.

    Saturday, February 17, 2018 9:18 PM

Answers

  • The fact that R and G have the same offset will probably somehow affect the attractivity of this structure. I think that you should not rely on A, R, G and B members.

    In order to convert the colours, check these examples:

    // From usual Color:

    System.Drawing.Color example = System.Drawing.Color.MediumVioletRed;

    WCell.Util.Graphics.Color result = new WCell.Util.Graphics.Color { ARGBValue = example.ToArgb() };

     

     

    // To usual Color:

    WCell.Util.Graphics.Color example = WCell.Util.Graphics.Color.MediumVioletRed;

    System.Drawing.Color result = System.Drawing.Color.FromArgb( example.ARGBValue );

     

    • Marked as answer by Zuher Laith Monday, February 19, 2018 8:01 PM
    Sunday, February 18, 2018 3:43 PM

All replies

  • Where do you see a "rgb value" in C#? .Net has the Color Structure and it is much like the one you are asking about. The main difference is that the order of the byte values are reversed.

    Just look at the struct you are asking about; it has the following in it:

    [FieldOffset(3)]
    public byte A;
    
    [FieldOffset(2)]
    public byte R;
    
    [FieldOffset(2)]
    public byte G;
    
    [FieldOffset(1)]
    public byte B;



    Sam Hobbs
    SimpleSamples.Info


    Saturday, February 17, 2018 11:55 PM
  • Where do you see a "rgb value" in C#? .Net has the Color Structure and it is much like the one you are asking about. The main difference is that the order of the byte values are reversed.

    So you basically mean like,
    // should output the color "Lime"
    public static readonly Color LimeColor2 = new Color() { R = 0, G = 255, B = 0 };
    
    // is the same like:
    public static readonly Color Lime = new Color() { ARGBValue = -16711936 };
    // ?
    could you please provide more info If I'm mistaken ?,
    Thanks !
    Sunday, February 18, 2018 1:30 AM
  • Try the following two lines:

    public static readonly System.Drawing.Color MicrosoftLime = new Color() { R = 0, G = 255, B = 0 };
    
    public static readonly WCell.Util.Graphics.Color WCellLime = new Color() { R = 0, G = 255, B = 0 };

    Then compare

    MicrosoftLime.ToArgb().ToString("X")
    
    WCellLime.ARGBValue.ToString("X")

    Since I don't know what you are using I can't be sure how to show those values but that is easy enough to do. Compare the values; they might be equal and they might not be.



    Sam Hobbs
    SimpleSamples.Info

    Sunday, February 18, 2018 2:19 AM
  • Try the following two lines:

    public static readonly System.Drawing.Color MicrosoftLime = new Color() { R = 0, G = 255, B = 0 };
    
    public static readonly WCell.Util.Graphics.Color WCellLime = new Color() { R = 0, G = 255, B = 0 };

    Then compare

    MicrosoftLime.ToArgb().ToString("X")
    
    WCellLime.ARGBValue.ToString("X")
    This is probably not a good idea,
    using "System.Drawing" and the other one both gave no value,

    It probably only works with the decimal color value .....
    any other suggestions ? ..

    • Edited by Zuher Laith Sunday, February 18, 2018 2:32 PM
    Sunday, February 18, 2018 2:18 PM
  • The fact that R and G have the same offset will probably somehow affect the attractivity of this structure. I think that you should not rely on A, R, G and B members.

    In order to convert the colours, check these examples:

    // From usual Color:

    System.Drawing.Color example = System.Drawing.Color.MediumVioletRed;

    WCell.Util.Graphics.Color result = new WCell.Util.Graphics.Color { ARGBValue = example.ToArgb() };

     

     

    // To usual Color:

    WCell.Util.Graphics.Color example = WCell.Util.Graphics.Color.MediumVioletRed;

    System.Drawing.Color result = System.Drawing.Color.FromArgb( example.ARGBValue );

     

    • Marked as answer by Zuher Laith Monday, February 19, 2018 8:01 PM
    Sunday, February 18, 2018 3:43 PM
  • Pick one out of the constant list to examine, this time I choose Red = -65536;

    As you can see, when -65536 is written as 32-bit Hex value, it is FFFF 0000. Therefore it has Alpha value of 255 (FF), Red value of 255 (FF), and then 0 for both Green and Blue.

    Likewise the value for Blue is -16776961 (FF00 00FF)

    However, the value of Green is a bit strange (-16744448 = FF00 8000), not sure whether the author intentionally set this value for some reason, but because of this, use the other constants there with caution.


    Monday, February 19, 2018 4:18 AM
    Answerer