我正在开发一个带有Flutter应用程序的平板电脑上的打卡钟,我需要这个功能。
我知道如何让摄像头显示和用户截图,但我到处寻找如何在3秒后自动自拍截图,但没有找到任何东西。
有人有这样的例子、教程或经验来制作这种东西吗?
发布于 2020-05-31 16:01:39
您可以使用Timer类在一定的持续时间后执行一些操作,如下所示
Timer(Duration(milliseconds: 3000), () {
//after 3 seconds this will be called,
//once this is called take picture or whatever function you need to do
takeScreenshot();
});如果您愿意,可以使用下面的代码截取此答案Take Screenshot Stackoverflow answer中提到的屏幕截图
takeScreenShot() async{
RenderRepaintBoundary boundary =
previewContainer.currentContext.findRenderObject();
ui.Image image = await boundary.toImage();
final directory = (await getApplicationDocumentsDirectory()).path;
ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.png);
Uint8List pngBytes = byteData.buffer.asUint8List();
print(pngBytes);
File imgFile =new File('$directory/screenshot.png');
imgFile.writeAsBytes(pngBytes);
}希望这能有所帮助!
https://stackoverflow.com/questions/62112957
复制相似问题