我正在尝试使用UIImageWriteToSavedPhotosAlbum()函数捕获并保存图片。这是我现在的代码。
@IBAction func CameraAction(sender: UIButton) {
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = .Camera
presentViewController(picker, animated: true, completion:nil)
基本上我用UIImagePickerController()类创建了一个名为picker的对象。我想使用UIImageWriteToSavedPhotosAlbum()函数,这样我就可以将上面代码拍摄的照片保存到相册中。我知道我需要使用总共4个参数才能正确使用UIImageWriteToSavedPhotosAlbum()函数。我想到第二,第三和第四参数我可以将它设置为零。我主要对第一个参数感到困惑。我知道它应该是一个UIImage。如何使用上面的代码作为UIImage获取我刚刚拍摄的图片?
答案 0 :(得分:0)
添加UIImagePickerControllerDelegate委托tinyour viewcontroller类
实施完成方法
func imagePickerController(picker:UIImagePickerController!, didFinishPickingMediaWithInfo info:NSDictionary)
{
if(picker.sourceType == UIImagePickerControllerSourceType.Camera)
{
// Access the uncropped image from info dictionary
var imageToSave: UIImage = info.objectForKey(UIImagePickerControllerOriginalImage) as UIImage
UIImageWriteToSavedPhotosAlbum(imageToSave, nil, nil, nil)
self.dismissViewControllerAnimated(true, completion: nil)
}
}