splitImage method
Splits the given image into vertical parts of specified maximum height
Implementation
Future<List<Uint8List>> splitImage(Uint8List uintImage, int maxHeight) async {
final List<Uint8List> parts = <Uint8List>[];
/// Load the image from bytes
///
final ui.Image image = await _loadImage(uintImage);
/// Calculate the number of vertical parts needed
///
final int yParts = (maxHeight == 0) ? 1 : (image.height / maxHeight).ceil();
final int partHeight = (image.height / yParts).round();
/// Iterate over each vertical part
///
for (int i = 0; i < yParts; i++) {
/// Extract a part of the image
///
final ui.Image partImage = await _extractImagePart(
image, 0, i * partHeight, image.width, partHeight);
/// Convert the extracted image part to byte data
///
final Uint8List? partBytes = await _imageToByteData(partImage);
/// Add the byte data of the part to the list if it's not null
///
if (partBytes != null) {
parts.add(partBytes);
}
}
return parts;
}