我正在尝试开发一个iOS应用程序,该应用程序使用iPhone相机捕获图像并将该图像保存到相机胶卷(或者我可以在以后访问它的某个地方)。我正在研究不同的方法来做到这一点,但我陷入困境。我希望有人可以指导我如何做到这一点的正确方向。这是我目前的代码:
import Foundation
import UIKit
class Camera: UIViewController, UIImagePickerControllerDelegate,UINavigationControllerDelegate {
@IBOutlet weak var Camera: UIButton!
@IBOutlet weak var PhotoLibrary: UIButton!
@IBOutlet weak var ImageDisplay: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func PhotoLibraryAction(sender: UIButton) {
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = .PhotoLibrary
presentViewController(picker, animated: true, completion:nil)
}
@IBAction func CameraAction(sender: UIButton) {
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = .Camera
presentViewController(picker, animated: true, completion:nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
ImageDisplay.image = info[UIImagePickerControllerOriginalImage] as? UIImage;
dismissViewControllerAnimated(true, completion: nil)
}
基本上我现在所拥有的是一个允许用户按下然后启动相机的按钮的系统。一旦相机启动,用户可以像平常一样使用相机拍照。拍摄照片后,用户将返回原始屏幕。我面临的问题是,在用户到达该点之后,我相当肯定,用户刚刚拍摄的图片仍然没有存储到设备中,这意味着我无法做到这一点。将来以后访问它。此外,我希望有人可以向我解释一旦它被保存到相机胶卷后访问图片的最佳方式。我知道有办法通过图片名称访问它,但我怎么知道这张照片会被调用?
非常感谢任何帮助。谢谢!
答案 0 :(得分:0)
您没有对代码进行任何保存,您需要将图像保存到相册,在解除ViewControllerAnimated'
之前添加此行UIImageWriteToSavedPhotosAlbum(ImageDisplay.image,nil,nil,nil)