- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Color c1 = image.GetPixel (7, 400);
Color c2 = Color.Blue;
Console.WriteLine (image.GetPixel (7, 400));
Console.WriteLine (Color.Blue);
Console.WriteLine (c1.Equals(c2));
控制台输出:
Color [A=255, R=0, G=0, B=255]
Color [Blue]
False
我是 C# 的新手,我不知道为什么会返回 false。谁能告诉我为什么这不起作用?
我正尝试在这种情况下使用它。
for (int i = 0; i < image.Height; i++) //loop through rows
{
for (int j = 0; j < image.Width; j++) //loop through columns
{
//Console.WriteLine ("i = " + i);
//Console.WriteLine ("j = " + j);
if ((image.GetPixel (i, j)) == Color.Blue)
{
return new Tuple<int, int>(i,j);
}
if (i == image.Height-1 && j == image.Width-1)
{
Console.WriteLine ("Image provided does not have a starting point. \n" +
"Starting points should be marked by Blue.");
Environment.Exit (0);
}
}
}
最佳答案
正如您已经注意到的,以下示例将返回 false:
Bitmap bmp = new Bitmap(1, 1);
bmp.SetPixel(0, 0, Color.Blue);
Color c1 = bmp.GetPixel(0, 0);
Console.WriteLine("GetPixel:" + c1);
Console.WriteLine("Color:" + Color.Blue);
Console.WriteLine("Equal?:" + c1.Equals(Color.Blue));
Console.ReadLine();
原因有点难以理解:
如果你查看Bitmap-Class的源代码,你会发现
public Color GetPixel(int x, int y) {
//lot of other code
return Color.FromArgb(color);
}
Color.Equals()
的文档说:
To compare colors based solely on their ARGB values, you should use the ToArgb method. This is because the Equals and Equality members determine equivalency using more than just the ARGB value of the colors. For example, Black and FromArgb(0,0,0) are not considered equal, since Black is a named color and FromArgb(0,0,0) is not.
https://msdn.microsoft.com/en-us/library/e03x8ct2(v=vs.110).aspx
因此,返回的 Color 不等于 Color.Blue
- 即使就 ARGB 值而言它是 Color.Blue
。
要绕过这个,使用:
Console.WriteLine("Equal?:" + c1.ToArgb().Equals(Color.Blue.ToArgb()));
作为示例的最后一行。
关于c# - Color.GetPixel().equals(Color.Blue) 的结果为假,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28920332/
当我们试图在 ListView (那里有很多项目)中拉到顶部(或末尾)时,我真的很想改变蓝色光芒(蓝色高亮)的颜色。 因此,伙计们,我想把这个颜色从蓝色改为橙色。 http://img835.imag
$('#toggle-linecolor').click(function () { chart.yAxis[0].update({ lineColor: li
给定两个简单的图形: library(igraph) g 111223345611 canonical 2(blue) vs 1(blue)->2(red),我们在Stack Overflow上找到
为什么在 java.awt.Color 类中定义了两个 Color 常量?例如 public static final Color blue; public static final Color BL
这个问题在这里已经有了答案: Can I use the id of an HTML element as a variable in JavaScript? [duplicate] (3 个答案)
我在大学作业中使用了 Flutter Blue,我需要创建一个应用程序来获取信息并将其传递给设备。像在任何应用程序中一样,此数据的传递必须是自动的(毕竟最终用户不应该寻找执行该过程所需的服务和特征)。
我正在对 Bitbucket Server 使用 Blue Ocean。我想要一个新的构建发生: 创建或更新拉取请求时 当 master 更新时(基本上,当 PR 合并到 master 时) 看来我可
我正在尝试使用 Microsoft 命名空间,我需要启用 Outlook 的“投票”选项,我正在 VBO - EmailPOP3/SMTP 上执行此操作。 当我引用命名空间 Microsoft.Off
我有一个蓝色的家伙(蓝色 Angular 色),我想在他周围的半圆中添加一些元素。 每个元素都是图像的容器和应该位于图像下方的文本范围。 我已经尝试过这个,但正如你看到的元素以这种方式旋转并且每个跨度
我试图更改.active状态的默认颜色。尝试更改.ui-btn-active。没用有任何想法吗??这是link 最佳答案 尝试使用!important子句将其添加为最后一条规则: .ui-btn-ac
我的 TCPListener 配置如下: this.tcpListener = new TcpListener(IPAddress.Any, config.portNum); 然后我(使用线程)设置一
我一直在尝试制作一个游戏,其中有一个显示红色或蓝色的大方 block ,用户必须相应地单击“v”或“b”。我最终以一种不令人满意和不专业的方式完成了这一部分(如果你能指导我找到更好的方法,那就太好了)
我必须从文件“main.csv”中读取并打印如下输出: Set 4,1095,Set 1 or 4 Set 2,18277,Set 2 or 3 Set 1 or 4,Set 4,944 Set 2,
我想知道是否可以更改选择器列表的默认蓝色。 这是一张说明我在说什么的图片: 在突出显示 S 的地方,是否可以将背景颜色(仅限所选尺码的颜色)更改为其他颜色?我尝试使用 select:active {
计划 public class Project_X { public static void main(String[] args){ byte x; int a=270
我只想通过 BLE 连接两部安卓手机。是否可以?因为根据我对使用 Android API 的理解,我只能连接支持 BLE 的设备,如智能 watch 耳机等。如果我运行 startLescan() 方
我现在一直在使用 flutter Blue,但我坚持以下几点:我正在使用在 https://github.com/pauldemarco/flutter_blue 上下载的示例应用程序,通过这里的基本
最近我安装了 Blue Ocean 插件,但是我不知道如何使用插件的 UI 来编辑或创建管道。 当我在 Blue Ocean 中创建新管道并与 GitLab 存储库连接时,我无法选择创建/编辑管道(J
我正在尝试使用 Blue Ocean 创建 Jenkins 管道,但是当我尝试使用 GitHub 生成的访问 token 连接到我的 GitHub 时,没有任何反应。但是,当我检查控制台时,我收到此错
我正在做一个涉及 Beaglebone blue 的个人项目。我想从任何地方远程访问它。我不确定这样做的最佳方法是什么。我知道我可以只转发一个相应的端口(不安全)或类似的东西,但我想避免太多的安全漏洞
我是一名优秀的程序员,十分优秀!