Saving a photo and using it immediately

前端 未结 3 949
悲哀的现实
悲哀的现实 2021-01-17 04:33

I have the following code for taking a photo and saving it to the camera roll. I need to be able to use it there and then after saving without having to go back into the gal

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-17 05:19

    You can get Path of the recently added image by camera this way:

    func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
        imagePicked.image = image
       if (cameraBool){
            var imageData = UIImageJPEGRepresentation(imagePicked.image, 0.6)
            var compressedJPGImage = UIImage(data: imageData)
            ALAssetsLibrary().writeImageToSavedPhotosAlbum(compressedJPGImage!.CGImage, orientation: ALAssetOrientation(rawValue: compressedJPGImage!.imageOrientation.rawValue)!,
            completionBlock:{ (path:NSURL!, error:NSError!) -> Void in
                println("\(path)")  //Here you will get your path
            })
        }
        self.dismissViewControllerAnimated(true, completion: nil);
    }
    

    Which will print path like this:

    assets-library://asset/asset.JPG?id=C5E0EB97-5D3D-41F9-8782-F48140144432&ext=JPG
    

提交回复
热议问题