getJPEGScreenShot method
Capturar screenshot en formato JPEG (menor tamaño)
Implementation
Future<String?> getJPEGScreenShot({GlobalKey? customKey}) async {
try {
final pngData = await getPNGScreenShot(customKey: customKey);
if (pngData == null) return null;
// Convertir PNG a JPEG (esto es una simplificación, en producción se podría usar un codec JPEG real)
// Por ahora retornamos PNG con calidad reducida
final key = customKey ?? _appRootKey;
if (key?.currentContext == null) return null;
final RenderRepaintBoundary boundary =
key!.currentContext!.findRenderObject() as RenderRepaintBoundary;
final double pixelRatio =
ui.PlatformDispatcher.instance.views.first.devicePixelRatio *
(_imageQuality * 0.7); // Calidad reducida para JPEG
final ui.Image image = await boundary.toImage(pixelRatio: pixelRatio);
final ByteData? byteData =
await image.toByteData(format: ui.ImageByteFormat.png);
if (byteData == null) return null;
final Uint8List imageBytes = byteData.buffer.asUint8List();
final String base64Image = base64Encode(imageBytes);
ObslyLogger.debug(
'JPEG screenshot captured (${imageBytes.length} bytes)');
return 'data:image/jpeg;base64,$base64Image';
} catch (e) {
ObslyLogger.error('Error capturing JPEG screenshot: $e');
return null;
}
}