【问题标题】:i want to save image in specific folder from UIImageView swift 3我想从 UIImageView swift 3 将图像保存在特定文件夹中
【发布时间】:2017-10-04 17:20:51
【问题描述】:

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

【问题讨论】:

  • 你不是保存到documentDirectory,你是保存到picturesDirectory
  • 我知道,但每次我重新运行令人困惑的模拟器时总是打印不同的路径....真的。
  • batter 选项是只创建一个应用程序名称的相册并将图像保存到其中。
  • 怎么样?你能给我一些代码或任何文章吗?
  • @HammerClass 检查我的答案

标签: ios iphone swift sqlite uiimageview


【解决方案1】:

创建一个我在链接中提供给您的 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>

【讨论】:

  • 谢谢@Himanshu 这真的很有帮助.. 需要最后一次支持有人否决了我的问题,请投票,我需要提高我的声誉....再次感谢
  • @HammerClass 好的,我给你,但请确保下次你提出完美的问题,这样没有人可以拒绝投票,你也可以放弃对我的回答投票,快乐编码。
  • 这很有帮助,但如果您添加一个可以从该特定目录获取所有图像的其他功能,它可能会更有帮助。谢谢
  • @HammerClass 你能更新你的库吗?其中有很多错误。如果可能的话,还可以通过这个库添加一个方法/函数来保存视频/mp4 文件。
  • 如果我想传递 UIImage 而不是 UIImageView 怎么办?我该怎么做?
猜你喜欢
  • 1970-01-01
  • 2013-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多