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
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
Use the ALAssetsLibrary, if you save the image using UIImageWriteToSavedPhotosAlbum, you don't get a pointer to it. More info.
Edit: I think the solution of @DharmeshKheni should work. My guess is that you read the cameraPath before this is set. In other words: I think you try to use the new picture before it's saved. Can you tell where the cameraPath is set, and where you read it?
You can use protocols/Delegation-pattern for this. See the Apple Doc.
Basically you create a Protocol in your class with the requiered functions, set a delegate variable, and then hand off your Image to the new View Controller. You can find a tutorial here.