/// <summary> /// Algorithm taken on http://www.codeproject.com/Articles/17044/Find-the-Nearest-Color-with-C-Using-the-Euclidean /// </summary> private MinecraftColor GetClosestMinecraftColor(ImageColor pixelColor) { // set a default color MinecraftColor nearestColor = MinecraftColor.Black; double minimumDistance = 500; double pixelRed = Convert.ToDouble(pixelColor.R); double pixelGreen = Convert.ToDouble(pixelColor.G); double pixelBlue = Convert.ToDouble(pixelColor.B); foreach (var color in _colorPalette) { // compute the Euclidean distance between the two colors var red = Math.Pow(color.Key.R - pixelRed, 2.0); var green = Math.Pow(color.Key.G - pixelGreen, 2.0); var blue = Math.Pow(color.Key.B - pixelBlue, 2.0); var temp = Math.Sqrt(blue + green + red); // explore the result and store the nearest color if (temp == 0.0) { nearestColor = color.Value; break; } else if (temp < minimumDistance) { minimumDistance = temp; nearestColor = color.Value; } } return(nearestColor); }
public GirlRating(double crazy, double hot, int roll, string advice) { Crazy = crazy; Hot = hot; Roll = roll; Advice = advice; // convenient to have it here, even though atm there are only few different ones. Url = new AsyncLazy <string>(async() => { try { using (var ms = new MemoryStream(NadekoBot.Images.WifeMatrix.ToArray(), false)) using (var img = new ImageSharp.Image(ms)) { var clr = new ImageSharp.Color(0x0000ff); const int minx = 35; const int miny = 385; const int length = 345; var pointx = (int)(minx + length * (Hot / 10)); var pointy = (int)(miny - length * ((Crazy - 4) / 6)); var p = new Pen(ImageSharp.Color.Red, 5); //using (var pointMs = File.ReadAllBytes("data/images/point.png").ToStream()) //using (var pointIMg = new ImageSharp.Image(pointMs)) //{ // img.DrawImage(pointIMg, 100, new ImageSharp.Size(100, 100), new Point(pointx, pointy)); //} string url; using (var http = new HttpClient()) using (var imgStream = new MemoryStream()) { img.Save(imgStream); var byteContent = new ByteArrayContent(imgStream.ToArray()); http.AddFakeHeaders(); var reponse = await http.PutAsync("https://transfer.sh/img.png", byteContent); url = await reponse.Content.ReadAsStringAsync(); } return(url); } } catch (Exception ex) { _log.Warn(ex); return(null); } }); }
public void PackUsingPointers() { Vector4 *sp = (Vector4 *)this.source.Pointer; byte * dp = (byte *)this.destination.Pointer; int count = this.Count; int size = sizeof(ImageSharp.Color); for (int i = 0; i < count; i++) { Vector4 v = Unsafe.Read <Vector4>(sp); ImageSharp.Color c = default(ImageSharp.Color); c.PackFromVector4(v); Unsafe.Write(dp, c); sp++; dp += size; } }