swift - Swift AVMutableVideoComposition 比例和中心计算
问题描述
我正在缩放 AVMutableVideoComposition 以适合我的全屏视图。
当我这样做时,它从左下角缩放,所以我试图将它居中。这是我的代码...
let scale = max(videoViewBounds.width/source.extent.size.width, videoViewBounds.height/source.extent.size.height)
let screenScale = UIScreen.main.scale
let translateX = (source.extent.size.width * scale) - videoViewBounds.width
let translateY = (source.extent.size.height * scale) - videoViewBounds.height
print("X: ", translateX)
print("Y: ", translateY)
let sourceTransform = CGAffineTransform.init(scaleX: scale * screenScale, y: scale * screenScale).translatedBy(x: -translateX/2, y: -translateY/2)
overlayFilter.setValue(source.transformed(by: sourceTransform), forKey: kCIInputBackgroundImageKey)
这给了我一个非常接近我想要的结果,但它有点偏离。如果我改变
-translate/2 to -translate/1.5
这似乎是完美的。但我不明白为什么。
有任何想法吗?还是更好的缩放和居中方式?
谢谢
解决方案
推荐阅读
- opencv - 如何使用 32 位色深图像转换为 pcd 或 ply 与 PCL
- wordpress - 自动将自定义分类设置为自定义帖子类型
- pandas - Pandas Dataframe 过滤并计算聚合结果
- android - 使用默认参数发送 Android Studio/Firebase 数据通知
- windows - 如何在詹金斯构建期间在批处理命令中传递特定参数
- ios - Target在Swift中分离线程的意义
- asp.net - 仅允许管理员用户访问文件夹
- c++ - 外部“C”或不外部“C” [g++ vs cl]
- javascript - 运行 mutool run script.js 时未定义“argv”
- mysql - 从 MySQL 5.6 升级到 Maria DB 10.2 后,数据库查询速度变慢