Hey guys I have a problem. I can take a picture with cocos2d and save it just fine and add it as a ccsprite, but when repeating the process, the image doesn't get updated. It's not because I'm not deleting the old file or old ccsprite. I think it has to do with "UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];". Any help would be appreciated :)
-(void)takePhoto {
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
#if TARGET_IPHONE_SIMULATOR
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
#else
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
#endif
imagePickerController.editing = YES;
imagePickerController.delegate = (id)self;
AppDelegate *app = (AppDelegate*) [[UIApplication sharedApplication] delegate];
[[app viewController] presentModalViewController:imagePickerController animated:YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
CGSize newSize;
//resizing image////
if ((UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)){
newSize = CGSizeMake(560, 560);
}
else {
newSize = CGSizeMake(280, 280);
}
UIImage *resizedImage = [self imageWithImage:image convertToSize:newSize];
if (resizedImage == nil){
NSLog(@"equal to nil");
}
else {
NSLog(@"not eqult to nil");
}
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectoryy = [paths objectAtIndex:0];
NSString* path = [documentsDirectoryy stringByAppendingPathComponent:
[NSString stringWithString: @"sample.JPG"] ];
NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager removeItemAtPath:path error:NULL];
///saving image as jpg///
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/sample.JPG"]];
// The value '1.0' represents image compression quality as value from 0.0 to 1.0
[UIImageJPEGRepresentation(resizedImage, 1.0) writeToFile:jpgPath atomically:YES];
NSError *error;
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]);
//add ccsprite test///
[self showNewMenu];
image = nil;
[image release];
info = nil;
[info release];
resizedImage = nil;
[resizedImage release];
[UIImagePickerControllerOriginalImage release];
//dimissing view controller//
[picker dismissModalViewControllerAnimated:YES];
picker = nil;
[picker release];
}