Hey guys, little question here, Been working on a different app then my last one but it is similar.
I have an app that takes an picture and stores it in "Documents".
Then in the next view controller it should load the image that was taken as the background but I am having some troubles loading the image as background in my next view.
Here is my code...
MainController.m: (take picture in this view)
SecondViewController.m (should load the image as background in this view)
My second view is not loading the picture that was taken in my first view as the background.
Any help appreciated
Thanks,
Steve!
I have an app that takes an picture and stores it in "Documents".
Then in the next view controller it should load the image that was taken as the background but I am having some troubles loading the image as background in my next view.
Here is my code...
MainController.m: (take picture in this view)
Code:
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSError *error;
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
// Create paths to output images
NSString *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.png"];
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.jpg"];
// Write a UIImage to JPEG with minimum compression (best quality)
// The value 'image' must be a UIImage object
// The value '1.0' represents image compression quality as value from 0.0 to 1.0
[UIImageJPEGRepresentation(image, 1.0) writeToFile:jpgPath atomically:YES];
// Write image to PNG
[UIImagePNGRepresentation(image) writeToFile:pngPath atomically:YES];
// Let's check to see if files were successfully written...
// You can try this when debugging on-device
// Create file manager
NSFileManager *fileMgr = [NSFileManager defaultManager];
// Point to Document directory
NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
// Write out the contents of home directory to console
NSLog(@"Documents directory: %@", [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]);
// Dismiss the camera
[self dismissModalViewControllerAnimated:YES];
}
- (NSString *)applicationDocumentsDirectory {
return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
}
SecondViewController.m (should load the image as background in this view)
Code:
- (void)viewDidLoad {
// self.view.backgroundColor = [UIColor redColor];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Documents/Test.png"]];
self.tiles = [[NSMutableArray alloc] init];
[self initPuzzle:@"myImage.png"];
[super viewDidLoad];
}
My second view is not loading the picture that was taken in my first view as the background.
Any help appreciated
Thanks,
Steve!
Last edited: