toPngBytes method

Future<Uint8List> toPngBytes()

Convert TxTextSpriteBlock back to a single image for testing/verification

Implementation

Future<Uint8List> toPngBytes() async {
  if (_lines.isEmpty) {
    throw Exception('_lines is empty: call rasterize() before toPngBytes()');
  }

  // create an image for the whole block
  var preview = img.Image(width: width, height: _totalHeight);

  // copy in each of the sprites
  for (int i = 0; i < lines.length; i++) {
    img.compositeImage(preview, lines[i].toImage(),
        dstY: (_displayLineMetrics[i].baseline - _displayLineMetrics[i].ascent).toInt());
  }

  return img.encodePng(preview);
}