使用ToArgb()后跟FromArgb()不会导致原来的颜色 [英] Using ToArgb() followed by FromArgb() does not result in the original color

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

问题描述

这不能正常工作

  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上 Col​​or.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屋!

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