我正在使用斯威夫特开发一个应用程序,与我的服务器,运行烧瓶通信。我希望能够拍一张照片,并上传到base64格式。目前,我使用的base64编码正在产生一个损坏的、不可用的图像。由于我正在使用AVCapturePhotoOutput,UIImage到base64教程对我来说没有用,因为斯威夫特在将AVCapturePhotoOutput转换为UIImage时遇到了困难。如何获得可靠工作的base64映像?如何将图像从AVCapturePhotoOutput转换为base64?谢谢您提前提供帮助!
@IBAction func takePhotoButtonPressed(_ sender: Any) {
let settings = AVCapturePhotoSettings()
sessionOutput.capturePhoto(with: settings, delegate: self)
}
func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Swift.Error?) {
let imageData = photo.fileDataRepresentation()
var base64String = imageData?.base64EncodedString()发布于 2021-06-09 23:49:19
当您最初配置照片设置时,请通过设置previewPhotoFormat请求预览图像。现在,您将能够获得照片的previewCGImageRepresentation,现在您在一个像素数据的世界,您将能够处理。
https://stackoverflow.com/questions/67912886
复制相似问题