我正在缩放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
这似乎很完美。但是我不明白为什么。
有什么想法吗?还是更好的缩放和居中方法?
谢谢