UIImage x 轴旋转

问题描述

我能够使用以下代码旋转 UIImageView。

var transform = CATransform3DIdentity
transform.m34 = -1.0 / 500.0
transform = CATransform3DRotate(transform,45.0 * .pi / 180.0,1.0,0.0,0.0)
imageView.layer.transform = transform

enter image description here

我可以得到一个处于相同状态的 UIImage 吗?

解决方法

据我所知,你不能在 UIImage 中做到这一点。 UIImage 用于表示各种图像数据,它确实不是视图。因此,我认为除非您直接操作图像数据来旋转原始图像,否则无法旋转图像,但我相信这不是一个好主意。

,

您可以将图像转换为 CIImage,然后将核心图像过滤器 CIPerspectiveTransform 应用到您的图像。谷歌搜索发现 this article 使用该转换。