我使用此代码将图像保存在图库中并且工作正常,图像保存在模拟器的图库中。
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var myImage : UIImage = UIImage(named: "sample")!
UIImageWriteToSavedPhotosAlbum(myImage, self, "image:didFinishSavingWithError:contextInfo:", nil)
}
func image(image: UIImage, didFinishSavingWithError error: NSError?, contextInfo:UnsafePointer<Void>) {
if error == nil {
let ac = UIAlertController(title: "Saved!", message: "Your altered image has been saved to your photos.", preferredStyle: .Alert)
ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
presentViewController(ac, animated: true, completion: nil)
} else {
let ac = UIAlertController(title: "Save error", message: error?.localizedDescription, preferredStyle: .Alert)
ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
presentViewController(ac, animated: true, completion: nil)
}
}
}
我正在使用Xcode 7.3 ans swift 2.0先谢谢。
答案 0 :(得分:0)
您可以使用UIImagePickerController选择已保存到图库的图像。委托函数imagePickerController:didFinishPickingMediaWithInfo:
将为您提供一个字典,其中包含有关所选图像的信息。 UIImage包含在UIImagePickerControllerOriginalImage
键下的此词典中。您可以阅读其他可用的密钥here。