drawBitmap method

  1. @override
dynamic drawBitmap(
  1. PrinterOffset offset,
  2. PrinterSize size,
  3. List<List<bool>> bytes
)
override

打印图片

context 内容

offset 偏移位置

bytes 位图内容, true:代表黑色 false:代表白色 二维数组 第一维纵 第二维横

Implementation

@override
drawBitmap(PrinterOffset offset, PrinterSize size, List<List<bool>> bytes) {
  Paint paint = Paint();
  paint.color = Color(0xFF000000);
  for (int y = 0; y < size.height!; y++) {
    for (int x = 0; x < size.width!; x++) {
      if (bytes[y].length > x && bytes[y][x] == true) {
        canvas!.drawRect(Rect.fromLTWH((offset.x! + x).toDouble(), (offset.y! + y).toDouble(), 1, 1), paint);
        // render a dark square on the canvas
      }
    }
  }
}