toPngBytes method
Convert TxTextSpriteBlock back to a single image for testing/verification startLine and endLine are inclusive
Implementation
Future<Uint8List> toPngBytes({required List<TxSprite> rasterizedSprites}) async {
if (rasterizedSprites.isEmpty) {
throw Exception('rasterizedSprites is empty');
}
// use the heights of the TxSprites to compose the image
int totalHeight = rasterizedSprites.fold(0, (sum, sprite) => sum + sprite.height);
// create an image for the whole block
var preview = img.Image(width: width, height: totalHeight);
// copy in each of the sprites
int currentY = 0;
for (TxSprite sprite in rasterizedSprites) {
img.compositeImage(preview, sprite.toImage(), dstY: currentY);
currentY += sprite.height;
}
return img.encodePng(preview);
}