System.Drawing.Color drawRedColor = System.Drawing.Color.Red;
System.Windows.Media.Color mediaColor = ?drawRedColor.ToMediaColor();?
Asked
Active
Viewed 3.2k times
33

Ash Burlaczenko
- 24,778
- 15
- 68
- 99

serhio
- 28,010
- 62
- 221
- 374
-
8@serhio - please, in the future, state your question in words. – Oded Nov 05 '10 at 10:04
-
Only that some people will see this and not see a question (so may vote to close as "not a real question"). Don't forget that we also want these questions to be found by google, and asking an actual question will help with getting this question in search results. – Oded Nov 05 '10 at 10:10
-
@Oded: I didn't find things to comment here. – serhio Nov 05 '10 at 10:11
-
@Oded: do *you* think that this is not a question? – serhio Nov 05 '10 at 10:12
-
Do you see a close vote? – Oded Nov 05 '10 at 10:12
-
@Oded, ok man, I think we understood each other :) – serhio Nov 05 '10 at 10:16
2 Answers
59
How about:
using MColor = System.Windows.Media.Color;
using DColor = System.Drawing.Color;
...
public static MColor ToMediaColor(this DColor color)
{
return MColor.FromArgb(color.A, color.R, color.G, color.B);
}
EDIT: Fixed the 'unpacking' of the ARGB.

Ani
- 111,048
- 26
- 262
- 307
-
-
-
3
-
2@serhio: I agree. It was mainly to prevent the horizontal scroll-bar from appearing. :) – Ani Nov 05 '10 at 10:20
-
-
-
@Mike Post: Works fine, as expected. `Console.WriteLine(System.Drawing.Color.Empty.ToMediaColor());` - Output: `#00000000`. – Ani Dec 18 '10 at 02:22
8
System.Windows.Media.Color mediaColor = System.Windows.Media.Color.FromRgb(Color.Red.R, Color.Red.G, Color.Red.B);

Kell
- 3,252
- 20
- 19
-
not correct approach, I don't need to transform the *Red* color, but a color variable :) – serhio Nov 05 '10 at 10:22
-
6hmmm... maybe you should extrapolate on the answer as I extrapolated on the "question" :) – Kell Nov 05 '10 at 17:34