Flutter 相机出现拉伸 [英] Flutter camera appears stretched

查看:72
本文介绍了Flutter 相机出现拉伸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在玩颤振,到目前为止我很喜欢它,但我在让相机工作时遇到了问题.

I've been playing around with flutter an i'm loving it so far, but I'm having an issue getting the camera working.

我按照此页面上的说明操作https://pub.dartlang.org/packages/camera 它有效.然而,相机被拉伸以适应手机屏幕,但图像扭曲并且比应有的高度更高.其他使用相机的应用程序似乎保持比例,有没有办法确保它不会被拉伸但仍然填满屏幕?

I follow the directions on this page https://pub.dartlang.org/packages/camera and it works. However, the camera is stretched so that it fits the phone screen, but the image is warped and taller than it should be. Other apps which use the camera seem to keep it in proportion, is there a way to ensure that it doesn't get stretched but still fills the screen?

推荐答案

基于 lase 的解决方案,此方法有效即使设备的纵横比与相机的比例不同:

Building upon the solution by lase, this works even when the aspect ratio of the device is different then the camera ratio:

final size = MediaQuery.of(context).size;
final deviceRatio = size.width / size.height;
return Transform.scale(
  scale: controller.value.aspectRatio / deviceRatio,
  child: Center(
    child: AspectRatio(
      aspectRatio: controller.value.aspectRatio,
      child: CameraPreview(controller),
    ),
  ),
);

这篇关于Flutter 相机出现拉伸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆