【发布时间】:2020-09-09 07:22:41
【问题描述】:
我的 Flutter 相机(插件“camera_camera”)和我放在它上面的图像有一个 AspectRatio 问题,透明层作为图层。
我将问题的屏幕截图发送给您。在屏幕截图中,您可以看到打开的相机,在它上方是我在它前面拍摄的照片。不幸的是,您可以在不同的地方看到它不匹配。
如何让相机显示与我之前从完全相同的位置拍摄的完全相同的比例?
如果这有帮助:我还录制了一个有关该问题的视频: https://danielederosa.de/downloads/flutter_issue.mp4
我的代码
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
if (!controller.value.isInitialized) {
return Container(
color: theme.colorScheme.onPrimary,
child: Center(child: CircularProgressIndicator()));
}
return Scaffold(
appBar: CupertinoNavigationBar(
backgroundColor: theme.colorScheme.primary,
border: Border.symmetric(
vertical: BorderSide.none, horizontal: BorderSide.none),
automaticallyImplyLeading: false,
leading: IconButton(
icon: Icon(
Icons.chevron_left,
size: 30,
color: theme.colorScheme.onPrimary,
),
onPressed: () => Navigator.pop(context),
),
middle: Text("Memories",
style: TextStyle(
color: theme.colorScheme.onPrimary,
fontSize: theme.textTheme.headline3.fontSize)),
),
body: Container(
child: Column(
children: [
Expanded(
child: Camera(
mode: CameraMode.normal,
imageMask: lastPicture != null
? new Positioned.fill(
child: new Opacity(
opacity: 0.3,
child: RotatedBox(
quarterTurns: 1,
child: new Image.file(
File(lastPicture),
fit: BoxFit.cover,
),
),
),
)
: Container(),
onFile: (File file) {
_workWithImage(file);
},
),
),
],
),
),
);
}
我还尝试使用aspectRatio: 3/4 将Camera 小部件包装到AspectRatio 小部件中,因为我保存的图像保存在这个aspectRatio 中。但没有成功。
你有什么办法解决这个问题吗?
【问题讨论】:
-
你试过用 BoxFit.fitWidth 代替 BoxFit.cover 吗?