getMergedImage method
obtain image Uint8List by merging layers
Implementation
Future<Uint8List?> getMergedImage({
int format = o.OutputFormat.png,
required int index,
}) async {
final imageLayers = layers[index];
Uint8List? image;
if (imageLayers?.length == 1 && imageLayers?.first is BackgroundLayerData) {
image = (imageLayers?.first as BackgroundLayerData).image.bytes;
} else if (imageLayers?.length == 1 &&
imageLayers?.first is ImageLayerData) {
image = (imageLayers?.first as ImageLayerData).image.bytes;
} else {
final controller = screenshotControllers[index];
image = await controller!.capture(pixelRatio: pixelRatio);
}
// conversion for non-png
if (image != null &&
(format == o.OutputFormat.heic ||
format == o.OutputFormat.jpeg ||
format == o.OutputFormat.webp)) {
var formats = {
o.OutputFormat.heic: 'heic',
o.OutputFormat.jpeg: 'jpeg',
o.OutputFormat.webp: 'webp'
};
image = await ImageUtils.convert(image, format: formats[format]!);
}
return image;
}