friend 我使用 AVFoundation 和 Swift 来拍摄照片。下面是我的代码
func captureImage(completion: @escaping (UIImage?, Error?) -> Void) {
guard let captureSession = captureSession, captureSession.isRunning
else { completion(nil, CameraControllerError.captureSessionIsMissing); return }
let settings = AVCapturePhotoSettings()
settings.flashMode = self.flashMode
self.photoOutput?.capturePhoto(with: settings, delegate: self)
self.photoCaptureCompletionBlock = completion
}
如何使用 AVFoundation 仅将图像捕获到文档应用程序目录? 我想也许可以捕获到标准相机胶卷,然后将图像保存到文档并从相机胶卷中删除。但我认为这是个坏主意。
如何仅保存到文档? 请帮忙
最佳答案
我还没有使用新的图像捕获流程,但我在文档中做了一些研究。
引用 AVCapturePhoto 中的文档:
When you capture photos with the AVCapturePhotoOutput class, your delegate object receives each resulting image and related data in the form of an AVCapturePhoto object. This object is an immutable wrapper from which you can retrieve various results of the photo capture.
如果你看AVCapturePhoto
在Xcode文档中,有一个方法fileDataRepresentation()
它将返回准备写入文件的图像数据(数据格式由您创建的 AVCapturePhotoSettings 中的设置确定)。您只需将该数据保存到您的文档目录即可。
AVCapturePhoto
还有一个功能cgImageRepresentation()
这将为您提供捕获照片的 CGImage,然后您可以根据需要对其进行处理。
关于ios - 如何使用 AVFoundation 将图像捕获到文档目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52237335/