2017-09-11 51 views
0
public static int DarkenColor1(int oleColor, float sngRatio) 
{ 
    int R= oleColor & 255; 
    int G= (int)(((long)oleColor & 65280L)/256L); 
    int B= (oleColor & 16711680)/65536;    
    return Information.RGB((int)(R/sngRatio), (int)(G/sngRatio), (int)(B/sngRatio));    
} 

如何在純C#代碼中替換Information.RGB,這是VB.NET?我不喜歡using Microsoft.VisualBasic在C#中替換Information.RGB#

+0

Color.FromArgb()? –

+0

Color.FromArgb返回Color,而不是int。 – qtg

+0

那麼'Color.FromArgb(r,g,b).ToArgb();' – Pikoh

回答

0

使用ColorTranslator.ToOle將指定的C#顏色結構轉換爲OLE顏色。

public static int DarkenColor1(int oleColor, float sngRatio) 
{ 
    int R= oleColor & 255; 
    int G= (int)(((long)oleColor & 65280L)/256L); 
    int B= (oleColor & 16711680)/65536;    
    //return Information.RGB((int)(R/sngRatio), (int)(G/sngRatio), (int)(B/sngRatio)); 
    return ColorTranslator.ToOle(Color.FromArgb((int)(R/sngRatio), (int)(G/sngRatio), (int)(B/sngRatio));    
}