ios - Get image name UIImagePickerController in Swift -


i use uiimagepickercontroller image phone library (ios). after edit mode put image uiimageview. want save image in core data use in view controllers

how can in swift. if not possible options have save image ?

another option can save image document directory of app , can retrieve image anywhere shown in below code:

func imagepickercontroller(picker: uiimagepickercontroller, didfinishpickingmediawithinfo info: [nsobject : anyobject]) {     self.dismissviewcontrolleranimated(true, completion: nil)     let tempimage = info[uiimagepickercontrolleroriginalimage] as! uiimage      // save image here document directory     saveimage(tempimage, path: fileindocumentsdirectory("tempimage"))  } 

here helper functions:

func saveimage (image: uiimage, path: string ) -> bool{      let pngimagedata = uiimagepngrepresentation(image)     //let jpgimagedata = uiimagejpegrepresentation(image, 1.0)   // if want save jpeg     let result = pngimagedata.writetofile(path, atomically: true)      return result  }  // documents directory  func documentsdirectory() -> string {     let documentsfolderpath = nssearchpathfordirectoriesindomains(nssearchpathdirectory.documentdirectory, nssearchpathdomainmask.userdomainmask, true)[0] as! string     return documentsfolderpath } // path file in directory  func fileindocumentsdirectory(filename: string) -> string {     return documentsdirectory().stringbyappendingpathcomponent(filename) } 

and way can retrieve image document directory:

@ibaction func setimage(sender: anyobject) {      imagev.image = loadimagefrompath(fileindocumentsdirectory("tempimage")) } 

and here helper function:

func loadimagefrompath(path: string) -> uiimage? {      let image = uiimage(contentsoffile: path)      if image == nil {          println("missing image at: (path)")     }     println("\(path)") // see path in case want go directory, using finder.     return image  } 

hope you.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -