gpt4 book ai didi

flutter - 点按即可对焦 Flutter 相机

转载 作者:行者123 更新时间:2023-12-04 11:15:02 29 4
gpt4 key购买 nike

一个简单但非常复杂的问题:为 Flutter 相机添加点击对焦功能的最佳方法是什么?
我在整个万维网上搜索了优雅的解决方案,但一无所获。
你有想法吗?

最佳答案

我可能会迟到,但你可以试试 adv_camera package .
这是一个简单的例子:

import 'package:adv_camera/adv_camera.dart';
import 'package:flutter/material.dart';

class CameraApp extends StatefulWidget {
final String id;

const CameraApp({Key? key, required this.id}) : super(key: key);

@override
_CameraAppState createState() => _CameraAppState();
}

class _CameraAppState extends State<CameraApp> {
List<String> pictureSizes = <String>[];
String? imagePath;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('AdvCamera Example'),
),
body: SafeArea(
child: AdvCamera(
initialCameraType: CameraType.rear,
onCameraCreated: _onCameraCreated,
onImageCaptured: (String path) {
if (this.mounted)
setState(() {
imagePath = path;
});
},
cameraPreviewRatio: CameraPreviewRatio.r16_9,
focusRectColor: Colors.purple,
focusRectSize: 200,
),
),
floatingActionButton: FloatingActionButton(
heroTag: "capture",
child: Icon(Icons.camera),
onPressed: () {
cameraController!.captureImage();
},
),
);
}

AdvCameraController? cameraController;

_onCameraCreated(AdvCameraController controller) {
this.cameraController = controller;

this.cameraController!.getPictureSizes().then((pictureSizes) {
setState(() {
this.pictureSizes = pictureSizes ?? <String>[];
});
});
}
}

关于flutter - 点按即可对焦 Flutter 相机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63961332/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com