[.net] Convert from D3DCOLORVALUE to System::Drawing::Color

This topic is 3835 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi, I have some troubles with conversion operators ! I have 2 classes which handle colors, one provided by the .NET framework (System::Drawing::Color) and the other by the DirectX SDK (D3DCOLORVALUE) They are basically the same, they juste store the RGB values and an alpha. The difference is one is using floats between 0 and 1 and the other ints between 0 and 255. So I'd like to create operators to implicitely converts one class to the other and vice versa. But I really don't understand how to do that ... I found a page in the MSDN saying that the correct way to define conversion operators is :
System::Drawing::Color op_Implicit(D3DCOLORVALUE value);

And when I use this syntax, it compiles fine. But when I try to use it by writing something like :
D3DCOLOR value src;
System::Drawing::Color dest;
dest = src;

The compiler tells me that no user-defined-conversion operator is available ... So I don't know what to do and google is not of much help on this :s Anybody has and idea ?? PS: I know how to create conversion functions as member of classes, but in my case, I don't have access to System::Drawing::Color nore D3DCOLORVALUE so I need to create a "global" conversion operator.

Share on other sites
I'm pretty new to .NET (I'm self-learning C# now), so pardon me if I grasp the wrong idea, but I thought you could use the help of this method:

Microsoft.DirectX.Direct3D.ColorValue.FromD3DColor(Microsoft.DirectX.PrivateImplementationDetails._D3DCOLORVALUE *Color)

and it's other siblings?

Share on other sites
I'm not using C# and MDX.
I'm using WinForms with C++ (managed C++) and the standard DX SDK. So I can't use your method.

For the moment, I use a function (something like : FromD3DCOLORVALUE(...)) which convert D3DCOLORVALUE to Color and another one which do the opposite, but I'm wondering if it's possible to create global conversion operators so that the conversion is implicitely done without me having to use a special function !

1. 1
2. 2
3. 3
Rutin
14
4. 4
khawk
11
5. 5

• 9
• 9
• 11
• 11
• 23
• Forum Statistics

• Total Topics
633672
• Total Posts
3013272
×