J'essaie de faire une application simple pour prendre une photo et enregistrer le fichier à la fois dans un UIImageview et dans le dossier de documents de sorte qu'il peut être rappelé à plus tard comme le UIImageview. Pour avoir une visibilité sur la création d'un fichier par l'application, j'ai activé l'application qui prend en charge le partage de fichiers iTunes dans le fichier .plist.enregistrer une image dans le répertoire documents - ne fonctionne pas - créer uniquement un fichier 0 octet
Problème: le fichier généré est zéro octet. J'ai essayé le format PNG et JPG.
- (IBAction)picImage:(id)sender {
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
//check to see if the device has camera capability
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
else
{
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
[self presentViewController:imagePicker animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//set the UIImageView to the selected image
playerImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];
//obtaining saving path
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *imagePath = [documentsDirectory stringByAppendingPathComponent:@"player.png"];
UIImage *editedImage = [UIImage imageWithContentsOfFile:imagePath];
NSData *imageData = UIImagePNGRepresentation(editedImage);
//NSData *imageData = UIImageJPEGRepresentation(editedImage,1.0);
// This actually creates the image at the file path specified, with the image's NSData.
[[NSFileManager defaultManager] createFileAtPath:imagePath contents:imageData attributes:nil];
//dismiss the imagepicker view controller
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];
}
Merci! Cela a fonctionné avec deux petites modifications à la dernière ligne. J'ai dû changer imgPicker en moi-même et changer la fonction abandonnée de rejectModal ... en celle mise à jour. - [self dismissViewControllerAnimated: YES achèvement: néant]; – jdeason
Bon travail ..... !!!! – NiravPatel