我想从相机中获取照片并使用它的名称保存在数据库中...
我已经使用了这些代码。我已成功拍照并添加到图像视图中,但现在我无法获取其名称(字符串值)
ImagePicker = [[UIImagePickerController alloc] init];
ImagePicker.delegate = self;
ImagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:ImagePicker animated:YES];
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
[ImagePicker dismissModalViewControllerAnimated:YES];
imageview.hidden=NO;
imageview.image = image;
NSDate *today = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd-MM-yyyy HH:mm:ss"];
NSString *dateString = [dateFormat stringFromDate:today];
// save image in document directoties
UIImage *image1=imageview.image;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory
NSData *pngData = UIImageJPEGRepresentation(image1,100.0);
NSString *filePath;
filePath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"image%@.jpg",dateString]]; //Add the file name
[pngData writeToFile:filePath atomically:YES]; //Write the file
NSLog(@"File Path is %@",filePath);
if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) //Optionally check if folder already hasn't existed.
{
NSLog(@"Unable to create Folder in Documents Directory");
}
}