Hammer Class
Hammer Class

Reputation: 371

i want to save image in specific folder from UIImageView swift 3

i want to save image from imageview to specific folder Image is coming from Sqlserver. and i want to save link of it in sqlite for further processing i have written this code which is saving image in document directory but every time path is different. Please tell me what to do ?

 let imageData = UIImagePNGRepresentation(imageee.image!)!
        let docDir = try! FileManager.default.url(for: .picturesDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
        let imageURL = docDir.appendingPathComponent("tmp.png")
        try! imageData.write(to: imageURL)

        print(imageURL.path)
        let newImage = UIImage(contentsOfFile: imageURL.path)!
       //aftersave.image = newImage
        aftersave.image = newImage

Upvotes: 3

Views: 2112

Answers (1)

Himanshu Moradiya
Himanshu Moradiya

Reputation: 4815

Create one swift class file that i give you in link and just call that class with below line.

// orignal_image was UIImageView 
CustomPhotoAlbum.sharedInstance.save(image: orignal_image) 

Class File Click Here

Most Important thing that you have to do add this line in info.plist file

<key>NSPhotoLibraryUsageDescription</key>
<string>YOUR APP need access to your camera roll and photo library</string>

Upvotes: 6

Related Questions