saveScreenshot static method

Future<String> saveScreenshot(
  1. Uint8List bytes
)

保存截屏图片到本地

Implementation

static Future<String> saveScreenshot(Uint8List bytes) async {
  try {
    // 获取临时目录路径
    final tempDir = await getTemporaryDirectory();
    final file = File('${tempDir.path}/screenshot.png');

    // 将图片数据写入文件
    await file.writeAsBytes(bytes);

    return file.path;
  } catch (e) {
    // 处理异常情况
    debugPrint('Error saving screenshot: $e');
    return '';
  }
}