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

时间:2017-05-06 08:20:04

标签: ios iphone swift sqlite uiimageview

我想将图像从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

1 个答案:

答案 0 :(得分:5)

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

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

Class File Click Here

您最重要的事情是在info.plist文件中添加此行

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