2016-09-24 179 views
0

我想在我的本地数据库中保存用户选择的颜色(这是一个Xamarin.Forms.Color),所以我使用ToString方法将它保存为字符串,保存的颜色使用以下语法:[Color: A = 1,R = 1,G = 0.400000005960464,B = 1,色调= 0.833333313465118,饱和度= 1,亮度= 0.699999988079071] 我想从数据库中检索它,但我必须将其转换回Xamarin.Forms。颜色(它有像Color.FromHex或Color.FromHlsa或Color.FromRgb ...)的方法Xamarin Forms Color

任何人都可以告诉我最好的方法来将其转换回来吗?

感谢

+0

如何从用户获取颜色?它是常量的列表,还是来自rgb或十六进制? – FetFrumos

+0

这是一个xamarin表单颜色列表 – Mireille

回答

0

Xamarin.FormsColor s可以从ARGB或从AHSL创建。从一种模式到另一种模式的转换是自动进行的,因此您不必将两种格式都保存在数据库中(您正在存储ARGBHSL)。

现在,有很多的方法来创建,由这些值的子集的颜色:

public Color(double r, double g, double b, double a); 
public static Color FromHex(string hex); //one of the following: #rgb, #argb, #rrggbb, #aarrggbb, the leading # is optional 
public static Color FromUint(uint argb); 
public static Color FromRgba(int r, int g, int b, int a); 
public static Color FromRgb(int r, int g, int b); 
public static Color FromRgba(double r, double g, double b, double a); 
public static Color FromRgb(double r, double g, double b); 
public static Color FromHsla(double h, double s, double l, double a = 1d); 

我敢肯定你会发现无论是构造或那些适合工厂方法你需要。

+0

感谢您的回答我会尝试将RGBA颜色保存为四个不同的变量并获得它从数据库中返回。 – Mireille