【发布时间】:2015-10-23 08:37:06
【问题描述】:
除了浏览照片库之外,我还启用了相机将照片添加到我的照片中
@IBAction func startCameraButtonTapped(sender: AnyObject) {
let startCameraController = UIImagePickerController()
startCameraController.delegate = self
startCameraController.sourceType = UIImagePickerControllerSourceType.Camera
startCameraController.allowsEditing = true
self.presentViewController(startCameraController, animated: true, completion: nil)
//invoiceImageHolder.image!.scaleAndRotateImage2(280)
//self.invoiceImageHolder.transform = CGAffineTransformMakeRotation((180.0 * CGFloat(M_PI)) / 180.0)
}
每个用户输入都可以删除,但现在我想知道相应的照片在哪里。当我浏览照片库时,我看不到使用我的应用程序拍摄的照片?这些照片存储在哪里?
[编辑] 这是我的 saveImage 过程
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let selectedImage = info[UIImagePickerControllerOriginalImage] as! UIImage
saveImage(selectedImage, path: fileInDocumentsDirectory("\(uniqueImageName)"))
// set the unique image reference in textfield
// Set photoImageView to display the selected image
self.invoiceImageHolder.image = selectedImage
// Dismiss the picker
dismissViewControllerAnimated(true, completion: nil)
}
func saveImage(image: UIImage, path: String) -> Bool{
let pngImageData = UIImagePNGRepresentation(image)
// let jpgImageData = UIImageJPEGRepresentation(image, 1.0)
let result = pngImageData?.writeToFile(path, atomically: true)
//print("Save result \(result)")
return result!
}
编辑嗯,我想我看到了照片的存储位置,但现在我如何浏览到它们以进行删除?
我想它在这里:
/var/mobile/Containers/Data/Application/CBFE9E9D-A657-4011-8B9F-EF0C9BB2C603/Documents/
但是每次我重新启动应用程序时,Application 和 /Documents 之间的部分都不一样??
仍然不是一个有效的解决方案,但对于像我这样的新手来说,这是一个有价值的阅读:http://www.techotopia.com/index.php/Working_with_Directories_in_Swift_on_iOS_8
[编辑 2] 使用此代码,我可以看到我的应用程序存储的所有时间。看到所有文件我有点惊讶
// Files stored in my app filemanager
let filemgr = NSFileManager.defaultManager()
do {
print("Start filemanager")
let filelist = try filemgr.contentsOfDirectoryAtPath(documentsDirectory())
for filename in filelist {
print(filename)
}
} catch {
print("No directory path \(error)")
}
// end filemanager
【问题讨论】:
标签: ios swift uiimagepickercontroller photolibrary