swift - `UIImagePickerControllerOriginalImage`、`UIImagePickerControllerCropRect`和`UIImagePickerControllerEditedImage`如何关联?
问题描述
我希望有人能解释这些值是如何相关的。(我会把我的解释放在一个自我回答中,看看它有多好)。
我正在开发一个功能,用户选择一个图像,然后提供一个方形裁剪边界,他们可以根据需要使用它。
所以,我正在UIImagePickerController
使用allowsEditing
文档不是特别有启发性->
指定应用于原始图像的裁剪矩形 https://developer.apple.com/documentation/uikit/uiimagepickercontroller/infokey/1619150-croprect
我正在做边缘案例测试,所以我裁剪了有人寄给我的全景图。这是我通过以下方式转储数据时的相关结果print
:
"UIImagePickerControllerOriginalImage": <UIImage: 0x6000014aed80> size {4032, 3024} orientation 1 scale 1.000000,
"UIImagePickerControllerCropRect": NSRect: {{0, 0}, {3071.9999999999995, 2307.710144927536}},
"UIImagePickerControllerEditedImage": <UIImage: 0x6000014a2290> size {826, 620} orientation 0 scale 1.000000,
解决方案
我的解释是:
取UIImagePickerControllerOriginalImage
(4032, 3024),然后用UIImagePickerControllerCropRect
, 从原点裁剪它,剃掉 ~3072 x 2308 之外的任何东西。
然后最终图像返回为 (826, 620),我猜裁剪的法师被缩放到值。(这三个的纵横比看起来非常一致)
推荐阅读
- html - 使页脚中的标签贴在左边,另一个贴在右边
- python - 增加 geopandas 中多边形几何的半径
- pygame - 我正在尝试使用 pygame 制作狂野西部游戏,但我无法让射击功能正常工作
- reactjs - Swiper 滑块效果在 React Js 中不起作用
- reactjs - 在 React Material UI 中的 ListItem 中显示
- mysql - 如何引用 SQL 函数中的输入?
- c# - 如何在 SQL Server 中使用 C# 将 [0][0] 打印为 001
- amazon-web-services - 为什么使用 AWS CloudFront 时出现 CORS 客户端错误?
- python - 如何获得最受好评的服务器 discord.py
- reactjs - TypeError:this.state.webOrders.map 不是函数