首页 > 解决方案 > `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,

标签: swiftuiimagepickercontroller

解决方案


我的解释是:

UIImagePickerControllerOriginalImage(4032, 3024),然后用UIImagePickerControllerCropRect, 从原点裁剪它,剃掉 ~3072 x 2308 之外的任何东西。

然后最终图像返回为 (826, 620),我猜裁剪的法师被缩放到值。(这三个的纵横比看起来非常一致)


推荐阅读