我使用 UIImagePickerController 将相机拍摄的图像保存到相册中。
UIImageWriteToSavedPhotosAlbum(myImage, self, #selector(saveimage(_:didFinishSavingWithError:contextInfo:)), nil)
图像已成功保存到相册,名称如 IMAGE_4000.JPG。我想获取直接加载图像的路径,而不选择它来实现基于 UI 的用户选择。
我尝试执行以下操作,但它只允许我访问应用程序的特定文件夹(例如/var/mobile/Containers/Data/Application/3C739746-<...>/Documents/) 而不是相册。
let path = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)
let fullpath = path[0].appending("/IMAGE_4000.JPG")
let url = URL(fileURLWithPath: fullpath)
let imagedata = try? Data(contentsOf: url)
let imagefromstorage = UIImage(data: imagedata!)
所以我的问题是,如何在通过 UIImageWriteToSavedPhotosAlbum 保存图像后获取图像名称以及访问它的相册路径,就像我在上面的代码片段中描述的那样?
最佳答案
UIImageWriteToSavedPhotosAlbum
会将图像保存到相机胶卷
相册中。这是一个不同的容器。
let path = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)
上面的语句将搜索您的应用程序容器中的文件。
所以两者是不同的东西。
关于ios - 保存到相机胶卷后从路径加载特定图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56441795/