gpt4 book ai didi

swift 3;照片未保存到照片库

转载 作者:行者123 更新时间:2023-11-28 06:31:43 25 4
gpt4 key购买 nike

此代码具有一个特殊的相机,该相机具有嵌套标题的相机。因此,当照片保存到照片库时,标题就在照片上。相机工作正常,但照片未保存。我只需要弄清楚如何将照片保存到照片库。我确实更改了 plist 以允许访问照片库和相机。

import Foundation
import UIKit



class ViewController: UIViewController, OverlayViewControllerDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

var picker = UIImagePickerController()

@IBAction func letsDoThis(_ sender: AnyObject) {
if UIImagePickerController.availableCaptureModes(for: .rear) != nil {
picker = UIImagePickerController()
picker.allowsEditing = false
picker.sourceType = .camera
picker.cameraCaptureMode = .photo
picker.showsCameraControls = false
let overlayViewController = OverlayViewController(nibName:"OverlayView", bundle: nil)
let overlayView: OverlayView = overlayViewController.view as! OverlayView
overlayView.frame = self.picker.view.frame

overlayView.delegate = self

picker.modalPresentationStyle = .fullScreen
present(picker, animated: true, completion: {


self.picker.cameraOverlayView = overlayView
})
} else {
let alert = UIAlertController(title: "No Camera", message: "That's weird. No camera.", preferredStyle: .alert)
let okay = UIAlertAction(title: "Alright Then.", style: .default, handler: nil)
alert.addAction(okay)
present(alert, animated: true, completion: nil)
}
}



override func viewDidLoad() {
super.viewDidLoad()
picker.delegate = self
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
picker.dismiss(animated: true, completion: nil)
}

//MARK: Image Picker Controller Delegates

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage
UIImageWriteToSavedPhotosAlbum(chosenImage, self,nil, nil)

dismiss(animated: true, completion: nil)
}

func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
dismiss(animated: true, completion: nil)
print("Canceled!!")
}

func didCancel(overlayView: OverlayView) {
dismiss(animated: true, completion: nil)
print("dismissed!!")
}
func didShoot(overlayView: OverlayView) {
picker.takePicture()
overlayView.cameraLabel.text = "Shot Photo"
print("Shot Photo")
}
}

最佳答案

这可能不是解决方案,但也许它会让您进一步了解为什么未保存图像(rmaddy 在问题评论中的提示)。要查看保存时是否有错误,请使用 completionTargetcompletionSelector 参数(另请参阅 docs ):

添加completionSelector方法:

func image(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeMutableRawPointer) {
guard error == nil else {
print("Error saving image: \(error)")
return
}
print("Image saved successfully")
}

UIImageWriteToSavedPhotosAlbum 改成这个

UIImageWriteToSavedPhotosAlbum(chosenImage, self, #selector(self.image(_:didFinishSavingWithError:contextInfo:)), nil)

关于 swift 3;照片未保存到照片库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40137596/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com