本文介绍了C#中找到相似的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要打电话与参数颜色的方法。但也有不少仅由一个灯罩颜色有所不同。我怎样才能找到它从我的颜色只有一点不同,例如古董白和浓汤的颜色。 这里的调色板。
位图LogoImg =新位图(file1.jpeg); //扩展名可以是一些其他的的System.Drawing.Color X = LogoImg.GetPixel(LogoImg.Width-1, LogoImg.Height-1); LogoImg.MakeTransparent(X); image1.Source = GetBitmapSource(LogoImg);解决方案
我发现这个程序的here :
颜色nearest_color = Color.Empty; 的foreach(对象o在网页颜色) { //计算两个颜色 //音符之间的欧几里得距离,即该α-组件未在本实施例$用于b $ b dbl_test_red = Math.Pow(Convert.ToDouble(((彩色)O).R) - dbl_input_red,2.0); dbl_test_green = Math.Pow(Convert.ToDouble (((彩色)O).G) - dbl_input_green,2.0); dbl_test_blue = Math.Pow(Convert.ToDouble (((彩色)O).B) - dbl_input_blue,2.0); TEMP =的Math.sqrt(dbl_test_blue + dbl_test_green + dbl_test_red); //探索的结果,并存储最接近的颜色如果(临时== 0.0) { nearest_color =(彩色)O; 中断; } ,否则如果(温度<距离) {距离=温度; nearest_color =(彩色)O; } }
I want to call a method with argument color. But there are a lot of colors which differ only by a shade. How can I find the colors which differ from my color only by little, for example AntiqueWhite and Bisque. Here's the color palette.
Bitmap LogoImg = new Bitmap("file1.jpeg");//the extension can be some other System.Drawing.Color x = LogoImg.GetPixel(LogoImg.Width-1, LogoImg.Height-1); LogoImg.MakeTransparent(x); image1.Source = GetBitmapSource(LogoImg);解决方案
I found this routine here:
Color nearest_color = Color.Empty; foreach (object o in WebColors) { // compute the Euclidean distance between the two colors // note, that the alpha-component is not used in this example dbl_test_red = Math.Pow(Convert.ToDouble(((Color)o).R) - dbl_input_red, 2.0); dbl_test_green = Math.Pow(Convert.ToDouble (((Color)o).G) - dbl_input_green, 2.0); dbl_test_blue = Math.Pow(Convert.ToDouble (((Color)o).B) - dbl_input_blue, 2.0); temp = Math.Sqrt(dbl_test_blue + dbl_test_green + dbl_test_red); // explore the result and store the nearest color if(temp == 0.0) { nearest_color = (Color)o; break; } else if (temp < distance) { distance = temp; nearest_color = (Color)o; } }
更多推荐
C#中找到相似的颜色
发布评论