我想从UIImageView swift 3中保存特定文件夹中的图像

Ham*_*ass 3 sqlite iphone uiimageview ios swift

我想将图像从imageview保存到特定文件夹图像来自Sqlserver.并且我想在sqlite中保存它的链接以便进一步处理我已经编写了这个代码,它在文档目录中保存图像但每次路径都不同.请告诉我该怎么办 ?

 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
Run Code Online (Sandbox Code Playgroud)

Him*_*iya 5

创建一个swift类文件,我在链接中给你,并用下面的行调用该类.

// orignal_image was UIImageView 
CustomPhotoAlbum.sharedInstance.save(image: orignal_image) 
Run Code Online (Sandbox Code Playgroud)

类文件单击此处

最重要的是你必须在info.plist文件中添加这一行

<key>NSPhotoLibraryUsageDescription</key>
<string>YOUR APP need access to your camera roll and photo library</string>
Run Code Online (Sandbox Code Playgroud)