开发者

Convert C Define Macro to C#

开发者 https://www.devze.com 2023-03-10 09:37 出处:网络
How can I convert this C define macro to C#? #define CMYK(c,m,y,k)((COLORREF)((((BYTE)(k)|((WORD)((BYTE)(y))<<8))|(((DWORD)(BYTE)(m))<<16))|(((DWORD)(BYTE)(c))<<24)))

How can I convert this C define macro to C#?

#define CMYK(c,m,y,k)       ((COLORREF)((((BYTE)(k)|((WORD)((BYTE)(y))<<8))|(((DWORD)(BYTE)(m))<<16))|(((DWORD)(BYTE)(c))<<24)))

I have been searching for a couple of days and have not been able to figure this out. An开发者_运维百科y help would be appreicated.


C# doesn't support #define macros. Your choices are a conversion function or a COLORREF class with a converting constructor.

public class CMYKConverter
{
    public static int ToCMYK(byte c, byte m, byte y, byte k)
    {
        return k | (y << 8) | (m << 16) | (c << 24);
    }
}

public class COLORREF
{
    int value;
    public COLORREF(byte c, byte m, byte y, byte k)
    {
        this.value = k | (y << 8) | (m << 16) | (c << 24);
    }
}


C# does not support C/C++ like macros. There is no #define equivalent for function like expressions. You'll need to write this as an actual method of an object.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号