使用ToArgb()后跟FromArgb()不会导致原来的颜色 [英] Using ToArgb() followed by FromArgb() does not result in the original color
问题描述
这不能正常工作
INT blueInt = Color.Blue.ToArgb();
颜色弗雷德= Color.FromArgb(blueInt);
Assert.AreEqual(Color.Blue,弗雷德);
有什么建议?
我使用NUnit和输出
失败:
预计:颜色[蓝]
不过是:颜色[A = 255,R = 0,G = 0,B = 255]
这个作品!
INT blueInt = Color.Blue.ToArgb();
颜色弗雷德= Color.FromArgb(blueInt);
Assert.AreEqual(Color.Blue.ToArgb(),fred.ToArgb());
从的 MSDN上 Color.operator ==文档
:
这个方法比较多 颜色结构ARGB值。 它也做了一些比较 状态标志。如果你想比较 两种颜色只是ARGB值 结构,使用比较它们 ToArgb方法。
我猜的状态标志是不同的。
This does not work
int blueInt = Color.Blue.ToArgb();
Color fred = Color.FromArgb(blueInt);
Assert.AreEqual(Color.Blue,fred);
Any suggestions?
[Edit]
I'm using NUnit and the output is
failed:
Expected: Color [Blue]
But was: Color [A=255, R=0, G=0, B=255]
[Edit]
This works!
int blueInt = Color.Blue.ToArgb();
Color fred = Color.FromArgb(blueInt);
Assert.AreEqual(Color.Blue.ToArgb(),fred.ToArgb());
From the MSDN documentation on Color.operator ==
:
This method compares more than the ARGB values of the Color structures. It also does a comparison of some state flags. If you want to compare just the ARGB values of two Color structures, compare them using the ToArgb method.
I'm guessing the state flags are different.
这篇关于使用ToArgb()后跟FromArgb()不会导致原来的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!