//private ImageTesting test1; public decimal scoreCalculator(Image image) { decimal white = whiteScore; decimal black = blackScore; //Get instance of new bitmap image. Image picture = image; //var picture = Bitmap.FromFile(image); using (var context = picture.CreateUnsafeContext()) { for (var w = 0; w < context.Width; w++) { for (var h = 0; h < context.Height; h++) { BumpKit.UnsafeBitmapContext.Pixel pixel = context.GetRawPixel(w, h); if (pixel.EqualsColor(Color.White)) { white++; } else if (pixel.EqualsColor(Color.Black)) { black++; } } } } //Formula for percentage // (count / totalcount) * 100); decimal score = Math.Floor((white / (white + black)) * 100); return(score); }
public string scoreCalculator() { decimal white = whiteScore; decimal black = blackScore; var picture = Bitmap.FromFile("~/Content/Images/new.bmp"); using (var context = picture.CreateUnsafeContext()) { for (var w = 0; w < context.Width; w++) { for (var h = 0; h < context.Height; h++) { BumpKit.UnsafeBitmapContext.Pixel pixel = context.GetRawPixel(w, h); if (pixel.EqualsColor(Color.White)) { white++; } else if (pixel.EqualsColor(Color.Black)) { black++; } } } } decimal score = Math.Floor((white / (white + black)) * 100); return(score.ToString()); }