当前位置:网站首页>[chapter 72 of the flutter problem series] a solution to the problem that pictures taken in the flutter using the camera plug-in are stretched
[chapter 72 of the flutter problem series] a solution to the problem that pictures taken in the flutter using the camera plug-in are stretched
2022-07-01 07:15:00 【Allen Su】
This is a 【Flutter Question Series No 72 piece 】, If it works , Welcome to the column .
Flutter SDK:2.5.0,Dart SDK:2.14,Android Studio :2021.2.1 Pathc 1.
One : Problem description
To customize the camera page in the project , So we use the official Camera plug-in unit , The code to build the camera view is as follows
/// Build camera view
Widget _cameraView() {
return CameraPreview(cameraController);
}
But when taking pictures , But there is a problem that the image is stretched , As shown in the figure below

After testing , Although the actual shooting effect is normal , But this kind of situation like the long leg effect is not what we want , How to solve this problem ?
Two : Solution
It's used here Transform
Component's scale attribute , Get the ratio of the aspect ratio of the camera to the pixel ratio of the device , As Transform Zoom ratio of , The modified code is as follows
/// Build camera view
Widget _cameraView() {
// Equipment size
final Size size = MediaQuery.of(context).size;
// Device pixel ratio
final double deviceRatio = size.width / size.height;
// Camera aspect ratio
final double aspectRatio = cameraController.value.aspectRatio;
return Center(
child: Transform.scale(
scale: aspectRatio / deviceRatio,
child: AspectRatio(
aspectRatio: aspectRatio,
child: Center(child: CameraPreview(cameraController)),
),
),
);
}
The effect picture after modification is as follows

You can see , The image is no longer stretched ,good.
Has your problem been solved ? Feel free to leave a comment in the comments section .
A gift of rose , Fragrance in hand , If you think the article is good , I hope you can give me one button three times , thank .
Google Of Flutter More and more fire , end 2022 year 6 month 29 Japan GitHub Target star has reached 142K,Flutter Determination is a trend , So as a front-end Developer , There is no reason not to study as soon as possible .
Conclusion
No matter you are Flutter Novices are still getting started , You might as well pay attention to , In the future, I will Flutter Common components in ( Contains source code analysis 、 Usage and precautions of components ) As well as possible problems CSDN Blog , I hope I can learn at the same time , It can also help more people .
边栏推荐
- EasyNVS云管理平台功能重构:支持新增用户、修改信息等
- Automated test platform (13): interface automation framework and platform comparison, application scenario analysis and design ideas sharing
- Reply and explanation on issues related to "online training of network security education in 2022"
- Programming examples of stm32f1 and stm32subeide infrared receiving and decoding of NEC protocol
- Operation and maintenance management system, humanized operation experience
- Do securities account opening affect the security of account opening
- K8s set up redis cluster
- ctfshow-web351(SSRF)
- 【Flutter 问题系列第 72 篇】在 Flutter 中使用 Camera 插件拍的图片被拉伸问题的解决方案
- Introduction to spark (one article is enough)
猜你喜欢
继妹变继母,儿子与自己断绝关系,世界首富马斯克,为何这么惨?
运维管理有什么实用的技巧吗
運維管理系統,人性化操作體驗
赌上了绩效,赢了公司CTO,我要搭DevOps平台!
如何制作专属的VS Code主题
ctfshow-web354(SSRF)
Solve the problem that the class defined in meta-inf.services cannot be read
Solution to the problem that objects in unity2021 scene view cannot be directly selected
女生适合学产品经理吗?有什么优势?
Pourquoi tant de gens sont - ils devenus des gestionnaires de produits? Quelles sont les perspectives de développement des gestionnaires de produits?
随机推荐
[lingo] find the shortest path problem of undirected graph
JSP - 分页
未来互联网人才还稀缺吗?哪些技术方向热门?
rclone常用子命令中文解释
STM32F1与STM32CubeIDE编程实例-NEC协议红外接收与解码
Which securities company is better or safer for mobile phone account opening
Rclone access web interface
图像风格迁移 CycleGAN原理
C语言实现【三子棋游戏】(步骤分析和实现源码)
How to permanently configure local opencv4.5.5 for vs2019
Solution to the problem that objects in unity2021 scene view cannot be directly selected
[classification model] Q-type cluster analysis
Paging in servlets and JSPS
iNFTnews | 从《雪崩》到百度“希壤”,元宇宙30年的16件大事
[image processing] image histogram equalization system with GUI interface
Buildreoot override mechanism
kdtree(kd树)笔记
JSP - paging
Servlet 和 JSP 中的分页
ctfshow-web352,353(SSRF)