I am taking a picture using the camera api and I am trying to take the image I get from it and pass it to another view. Can someone please help me with this? Thanks
I am taking a picture using the camera api and I am trying to take the image I get from it and pass it to another view. Can someone please help me with this? Thanks
I just added a link to a thread on sharing data in my signature. That should give you what you need.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
But the problem is I am trying to get the bold line in this code to be shared to another view controller.
Code:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// Dismiss the picker
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
// Get the image from the result
UIImage* image = [info valueForKey:@"UIImagePickerControllerOriginalImage"];
// Get the data for the image as a PNG
NSData* imageData = UIImagePNGRepresentation(image);
// Give a name to the file
// NSString* imageName = "MyImage.png";
NSString *imageName = @"MyPic.png";
// Now, we have to find the documents directory so we can save it
// Note that you might want to save it elsewhere, like the cache directory,
// or something similar.
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
// Now we get the full path to the file
NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imageName];
// and then we write it out
[imageData writeToFile:fullPathToFile atomically:NO];
return;
}
So I am trying to take MyPic.png and pass it to another view. But I am not sure how to share an image as I have never tried it before. Hopefully you can help me, thanks!
But the problem is I am trying to get the bold line in this code to be shared to another view controller.
Code:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// Dismiss the picker
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
// Get the image from the result
UIImage* image = [info valueForKey:@"UIImagePickerControllerOriginalImage"];
// Get the data for the image as a PNG
NSData* imageData = UIImagePNGRepresentation(image);
// Give a name to the file
// NSString* imageName = "MyImage.png";
NSString *imageName = @"MyPic.png";
// Now, we have to find the documents directory so we can save it
// Note that you might want to save it elsewhere, like the cache directory,
// or something similar.
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
// Now we get the full path to the file
NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imageName];
// and then we write it out
[imageData writeToFile:fullPathToFile atomically:NO];
return;
}
So I am trying to take MyPic.png and pass it to another view. But I am not sure how to share an image as I have never tried it before. Hopefully you can help me, thanks!
The line you marked in bold is a string, not an image.
The method you're posting takes an image the user picks and saves it to a file in the documents directory.
What do you want to share with another view controller? The image the user selected, in memory? The path to the image file on disk? The filename of the image file?
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
The line you marked in bold is a string, not an image.
The method you're posting takes an image the user picks and saves it to a file in the documents directory.
What do you want to share with another view controller? The image the user selected, in memory? The path to the image file on disk? The filename of the image file?
I want to share the string. I am trying to get it by accessing the path to the image file on disk. So the user takes a picture, I get that picture and share it to another view controller.
I want to share the string. I am trying to get it by accessing the path to the image file on disk. So the user takes a picture, I get that picture and share it to another view controller.
So add a new property to your second view controller, imageFileName.
@property (nonatomic, rertain) imageFileName;
In your imagePickerViewController, add code to install the image name into the second view controller:
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.