This question already has answers here:
iPhone: How do I get the file path of an image saved with UIImageWriteToSavedPhotosAlbum()?
(7个答案)
三年前关闭。
我用这段代码将图像保存在gallery中,它工作正常,图像保存在simulator的gallery中。
import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        var myImage : UIImage = UIImage(named: "sample")!
        UIImageWriteToSavedPhotosAlbum(myImage, self, "image:didFinishSavingWithError:contextInfo:", nil)
    }

    func image(image: UIImage, didFinishSavingWithError error: NSError?, contextInfo:UnsafePointer<Void>) {
        if error == nil {
            let ac = UIAlertController(title: "Saved!", message: "Your altered image has been saved to your photos.", preferredStyle: .Alert)
            ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
            presentViewController(ac, animated: true, completion: nil)
        } else {
            let ac = UIAlertController(title: "Save error", message: error?.localizedDescription, preferredStyle: .Alert)
            ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
            presentViewController(ac, animated: true, completion: nil)
        }
    }
}

如何获取刚保存在gallery中的图像的路径?
然后使用该路径,如何从gallery获取图像并在应用程序中使用它?
我正在使用Xcode 7.3和swift 2.0,谢谢。

最佳答案

您可以使用UIImagePickerController选择已保存到库中的图像。delegate函数imagePickerController:didFinishPickingMediaWithInfo:将为您提供一个字典,其中包含有关所选图像的信息。UIImage包含在此字典中的UIImagePickerControllerOriginalImage键下。您可以阅读其他可用键here

关于ios - 在将图像路径保存在图库中的同时获取图像路径,然后稍后使用swift在iOS中使用路径检索该图像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37663824/

10-14 23:12
查看更多