toBlackAndWhite static method

List<int> toBlackAndWhite(
  1. List<int> rgba, {
  2. int tolerance = 75,
})

Implementation

static List<int> toBlackAndWhite(List<int> rgba, {int tolerance = 75}) {
  int white = 255;
  int black = 0;
  rgba = toGrayScale(rgba);
  int whitest = getWhitest(rgba);
  for (int i = 0, len = rgba.length; i < len; i += 4) {
    int value = (rgba[i] < (whitest - tolerance)) ? black : white;
    rgba[i] = value;
    rgba[i + 1] = value;
    rgba[i + 2] = value;
  }
  return rgba;
}