简体   繁体   中英

swift3 how to save Photo info in SQLite from photo library?

swift3

hello, i want to save photo in sqlite and load it anytime.

first, choice photo from photo library. second, save it in sqlite ( how? ) last, i want to show the photo from sqlite information

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

    let mediaType = info[UIImagePickerControllerMediaType] as! NSString
    self.dismiss(animated: true, completion: nil)

    if mediaType.isEqual(to: kUTTypeImage as String) {
        let image = info[UIImagePickerControllerOriginalImage] as! UIImage
        let imageData = UIImagePNGRepresentation(image)
        let strBase64:String = (imageData?.base64EncodedString(options: .lineLength64Characters))!
        imageInfo = strBase64 // <imageInfo will saved in sqlite

        imageView.image = image
    }
}

this code is how to im bring photo.

You should save only the path of photo in sqlite and use that path to show photo in future. So your steps should be:

1) Get photo from photo library

2) Save photo in document directory

3) store the path of photo in sqlite

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM