AVCapture的 layerPointConverted返回的设备坐标不正确
我有一个简单的应用,专为iPad Pro M4和 iPad Air M3设计,使用AVCapture功能显示实时视图。拍照时使用的是常见的AVCam代码。我想应用自定义的曝光点。下面是把设备点转换为图层点的代码。
let point = CGPoint(x: 340, y : 445)
let devicePoint = cameraPreview.layer.captureDevicePointConverted(fromLayerPoint: point)
然后使用这个devicePoint来设置曝光点。
下面是拍照时获取同一个曝光点的代码。
let point = cameraPreview.layer.layerPointConverted(fromCaptureDevicePoint: videoDevice.exposurePointOfInterest)
这个点在设置时应该保持一致,但在y 坐标上却显示不同的数值。关键点是在cameraPreview图层上我将videoGravity设置为resizeAspectFill。不过如果只使用resize,则会得到正确的数值。
有没有人遇到过类似的问题?有什么解决办法吗?
解决方案
The problem is you are using resizeAspectFill and the way resizeAspectFill works is it filled the image based on the screen size hence image get cropped. What you can try instead is either use one them from below (which may be not recommended for camera UX)
resize
resizeAspect
or get the tap point then set to the exposure point and convert back to your UI point like this
let cameraPoint = previewLayer.captureDevicePointConverted(fromLayerPoint: tapPoint)
device.exposurePointOfInterest = cameraPoint
device.exposureMode = .continuousAutoExposure
// To draw UI later
let uiPoint = previewLayer.layerPointConverted(fromCaptureDevicePoint: cameraPoint)
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。