首页 > 解决方案 > 如何快速将字符串描述保存到图像文档中?

问题描述

出于澄清原因,我正在尝试为图像文档编写一些描述。是否可以像在 Android 中那样为文档文件编写描述?如果有怎么办?

开发人员说明:对于那些不知道的人,保存到照片应用程序的选项非常有限。(您不能命名您的文件,将扩展名从 Jpeg 更改为 png,创建子目录等)

下面是将图像保存到文档目录的代码

//将图像保存在文档目录中:

  let fileManager = FileManager.default
        let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] + "/swiper.jpg"
        let imageData = UIImageJPEGRepresentation(#imageLiteral(resourceName: "swiper"), 0.5)
        fileManager.createFile(atPath: path, contents: imageData, attributes: nil)

Github 代码链接:

https://github.com/artemnovichkov/FileSharingExample

标签: iosswiftfilesave

解决方案


推荐阅读