convertBlackWhiteImageToBinary function

BitMatrix convertBlackWhiteImageToBinary(
  1. Image image
)

Converts the image into a bit matrix with one bit per pixel. A bit is set (1) when the corresponding pixel in the image is black. Otherwise the pixel is unset (0). A pixel is considered black if its red, green and blue channel are zero and it's alpha channel, if present, is 255.

Implementation

BitMatrix convertBlackWhiteImageToBinary(Image image) {
  final out = BitMatrix.createEmpty(image.width, image.height);
  for (var y = 0; y < image.height; y++) {
    for (var x = 0; x < image.width; x++) {
      out.set(x, y, _isBlackPixel(image, x, y));
    }
  }
  return out;
}