-1

I have the following code in C#:

Color c;
// Setup ARGB COLOR 80, 20, 86, 20
            c = Color.FromArgb(80, 20, 86, 20);

            int r, g, b, a;

            r = c.R;
            g = c.G;
            b = c.B;
            a = c.A;

            MessageBox.Show("The color in RGBA format is : " +
                            r.ToString() + " " + 
                            g.ToString() + " " + 
                            b.ToString() + " " + 
                            a.ToString());

I am attempting to convert the color to RGBA format. I was thinking that it would just be:

20, 86, 20, 80 <== RGBA ??

But the color does not render the same. Am I missing something? Is code needed to convert this?

Thanks Before Hand

crashmstr
  • 28,043
  • 9
  • 61
  • 79
user3657279
  • 188
  • 2
  • 12
  • Please post more code and rephrase your question, how are you creating a color from the RGBA format as opposed to the ARGB format? – Dai Oct 01 '14 at 19:05
  • Do you need RGBA to create a new Color, or you're trying to get RGBA from the color you created? – Pierre-Luc Pineault Oct 01 '14 at 19:09
  • I am trying to create the RGBA color from the ARGB COLOR: 80, 20, 86, 20 – user3657279 Oct 01 '14 at 19:11
  • Apparently [not the same](https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=RGBA+vs.+ARGB) – crashmstr Oct 01 '14 at 19:14
  • 2
    "does not render the same" - *how* are you rendering both the ARGB and RGBA colors? – Hans Kesting Oct 01 '14 at 19:14
  • 1
    Related: [Fast Converting RGBA to ARGB](http://stackoverflow.com/questions/11259391/fast-converting-rgba-to-argb) – crashmstr Oct 01 '14 at 19:15
  • crashmstr, the link you provided "Related" I already had seen. But that was of no help. Thanks anyways. – user3657279 Oct 01 '14 at 19:23
  • Do you mean `Color c2 = Color.FromArgb(r,g,b,a)` ?? That wouldn't make any sense.. Not even : `Color c2 = Color.FromArgb(a, r,g,b)` imo.. either you access a Color (ARGB) or a bitmap buffer (BGRA), no use converting I can think of.. Can you explain what you are trying to achieve? – TaW Oct 01 '14 at 19:56

2 Answers2

0
Color c;
// Setup ARGB COLOR 80, 20, 86, 20
            c = Color.FromArgb(80, 20, 86, 20);

            int r, g, b, a;

            r = c.R;
            g = c.G;
            b = c.B;
            a = c.A;
String rgba = String.Format("rgba({0},{1},{2},{3})", c.R, c.G, c.B, c.A);

OR FROM HEX TO RGBA

Color c = ColorTranslator.FromHtml(hexcolor);
string rgba= String.Format("rgba({0},{1},{2},{3})", col.R, col.G, col.B, c.A);
Ifeanyi Chukwu
  • 3,187
  • 3
  • 28
  • 32
-1

I found no way to do this programatically. (If anyone knows how please let me know) I ended up doing a trial and error until I found the correct value.

FROM ARGB: 80, 20, 86, 20

To RGBA: 20, 86, 20, .3 (Note the .3 is approximate since I am not sure how to calculate the alpha)

Thanks

user3657279
  • 188
  • 2
  • 12
  • 2
    This is as little informative as the question. I still don't know the problem neither the solution. – Mephy Oct 01 '14 at 20:21
  • Apparently you missed my "related" link: [Fast Converting RGBA to ARGB](http://stackoverflow.com/questions/11259391/fast-converting-rgba-to-argb) – crashmstr Oct 02 '14 at 13:09