1
我正在使用Swift和Xcode 6構建iOS應用程序。我已經實現了從UIImagePickerController中選擇圖像並設置爲UIImageView的功能。如何從UIImagepickercontroller中選擇後保存圖像
這是我從代碼的UIImagePickerController選擇圖像:
@IBAction func loadImageButtonTapped(sender: UIButton) {
imagePicker.allowsEditing = false
imagePicker.sourceType = .PhotoLibrary
// imagePicker.sourceType = .Camera
//imagePicker.sourceType = .SavedPhotosAlbum
presentViewController(imagePicker, animated: true, completion: nil)
}
// MARK: - UIImagePickerControllerDelegate Methods
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
// imageView.contentMode = .ScaleAspectFit
imageView.image = pickedImage
}
dismissViewControllerAnimated(true, completion: nil)
}
func imagePickerControllerDidCancel(picker: UIImagePickerController) {
dismissViewControllerAnimated(true, completion: nil)
}
現在我發現保存這個形象,當用戶在應用程序再次降臨,我可以得到圖像,並顯示在一個最好的方法uiimageview。
有些人可以幫我實施這個。
幫助表示讚賞!
在此先感謝!
請你解釋一下我的會是什麼時候的DestinationPath我得在viewDidLoad.let loadedImage =的UIImage的UIImage的(contentsOfFile:的DestinationPath) – Daljeet
您可以像保存圖像一樣執行相同的操作來獲取目標路徑。即'let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory,.UserDomainMask,true)[0] as String ... etc' – villy393
感謝它工作正常 – Daljeet