无法将类型'double'隐式转换为'int'。存在显式转换(您是否错过了演员?) [英] Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)

查看:153
本文介绍了无法将类型'double'隐式转换为'int'。存在显式转换(您是否错过了演员?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用下面的代码来查找白色像素的阈值,以便我可以区分白色像素和白色像素。关于如何改进上面的代码以避免我得到的错误的任何想法?







 Color colorValue = image.GetPixel(x,y); 
var averageValue =((int)colorValue.R +(int)colorValue.B +(int)colorValue.G)/ 3; //得到黑白的平均值
int threshold = averageValue * 0.9;

解决方案

是的你可以

动态数组c#...... [ ^ ]





列表< double> list = new List< double>();

list.Add(12);

list.Add(12);

控制台。 WriteLine(列表[1]);





如果有效请标记解决方案或评价解决方案

  double  averageValue =(( double )colorValue.R +( double )colorValue.B +( double )colorValue.G)/ 3d;  //  获取黑白的平均值 
int threshold =( int )(averageValue * 0 .9d);


是的,你可以

动态数组c#...... [ ^ ]

i'm using the code below to find a threshold value of white pixels so that i can distinguish white pixel's from "whiter" ones.Any ideas on how to improve the code above to avoid the error I'm getting?



Color  colorValue=image.GetPixel(x,y);
       var averageValue = ((int)colorValue.R + (int)colorValue.B + (int)colorValue.G)/3; // get the average for black and white
      int  threshold=averageValue * 0.9;

解决方案

yes you can
dynamic array c#......[^]


List<double> list = new List<double>();
list.Add(12);
list.Add(12);
Console.WriteLine(list[1]);


if it work please mark are solution or rate the solution


double averageValue = ((double)colorValue.R + (double)colorValue.B + (double)colorValue.G)/3d; // get the average for black and white
      int  threshold=(int)(averageValue * 0.9d);


yes you can
dynamic array c#......[^]


这篇关于无法将类型'double'隐式转换为'int'。存在显式转换(您是否错过了演员?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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