sách gpt4 ăn đã đi

ios - 将具有透视变换的 UIView 转换为 UIImage

In lại 作者:搜寻专家 更新时间:2023-10-31 23:00:21 24 4
mua khóa gpt4 giày nike

我想将具有透视变换的 UIView 转换为 UIImage,但我得到的图像没有经过变换。我怎样才能保持转型?

我正在使用以下代码对 UIView 进行透视变换:

    var rotationAndPerspectiveTransform = CATransform3DIdentity
rotationAndPerspectiveTransform.m34 = 1.0 / -500
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, 45.0 * CGFloat(M_PI) / 180.0, 1.0, 0.0, 0.0)
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, 45.0 * CGFloat(M_PI) / 180.0, 0.0, 1.0, 0.0)
self.photoImageView.layer.transform = rotationAndPerspectiveTransform

然后将带有透视变换的 UIView 转换为 UIImage:

    UIGraphicsBeginImageContextWithOptions(view.bounds.size, false, 0.0)
view.layer.renderInContext(UIGraphicsGetCurrentContext()!)
hãy để hình ảnh = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

结果我得到了正确的图像,但没有透视

câu trả lời hay nhất

您可以使用 UIView 方法 drawViewHierarchyInRect。它会将完整 View 层次结构的快照呈现为在当前上下文中在屏幕上可见。

像这样尝试:

UIGraphicsBeginImageContextWithOptions(view.bounds.size, false, 0.0)
view.drawHierarchy(in: view.bounds, afterScreenUpdates: true)
hãy để hình ảnh = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

关于ios - 将具有透视变换的 UIView 转换为 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36755980/

24 4 0
Đề xuất bài viết: php - jQuery html() 和 &
Đề xuất bài viết: node.js - I/O 绑定(bind)和 CPU 绑定(bind)
Đề xuất bài viết: php - 刷新 PHP include()
Đề xuất bài viết: javascript - 在 Ionic App 中以横向全屏播放视频
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress