使用ToArgb()和FromArgb()不会生成原始颜色 [英] Using ToArgb() followed by FromArgb() does not result in the original color

查看:355
本文介绍了使用ToArgb()和FromArgb()不会生成原始颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不起作用

  int blueInt = Color.Blue.ToArgb 
Color fred = Color.FromArgb(blueInt);
Assert.AreEqual(Color.Blue,fred);

有任何建议吗?





我正在使用NUnit,输出为



失败:



预期:颜色[蓝色]



但是:Color [A = 255,R = 0,G = 0,B = 255] p>



这可以使用!

  int blueInt = Color.Blue.ToArgb(); 
Color fred = Color.FromArgb(blueInt);
Assert.AreEqual(Color.Blue.ToArgb(),fred.ToArgb());

解决方案

MSDN文档 Color.operator ==


此方法比比较多个结构的
ARGB值。
它还比较了一些
状态标志。如果你想比较
只是两个Color
结构的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆