I am trying to make a simple application using XCode 4.5 which would allow the user to chose any particular image via accessing his photo library, then submit that image for recognition with the help of the Tesseract library.
我正在尝试使用XCode 4.5制作一个简单的应用程序,它允许用户通过访问他的照片库来选择任何特定图像,然后在Tesseract库的帮助下提交该图像以进行识别。
The problem is that I do not know how to further save the selected user picture, In other words, I can provide the user with an option for going in the picture library and let him chose a picture, but I do not how to then save that selected picture so that it can be further processed.
问题是我不知道如何进一步保存所选择的用户图片,换句话说,我可以为用户提供进入图片库的选项,让他选择一张图片,但我不知道如何保存选择的图片,以便可以进一步处理。
I hope i made it clear, Appreciate your help.
我希望我说清楚,感谢你的帮助。
3 个解决方案
#1
0
What you need to do is save the image data after selection inside the following delegate - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
You can get the image via the key UIImagePickerControllerOriginalImage
in the info dictionary and possibly assign it to an imageview or save it as mentioned by @Kalpesh. Check out apple's documentation for more info. Also check out this good tutorial that shows how to pick photos from the photo album or the camera.
您需要做的是在以下委托中选择后保存图像数据 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {您可以通过信息字典中的密钥UIImagePickerControllerOriginalImage获取图像,也可能将其分配给imageview或按@Kalpesh所述保存。查看Apple的文档以获取更多信息。另请参阅这个很好的教程,该教程介绍如何从相册或相机中挑选照片。
#2
3
Try this, Save image:
试试这个,保存图片:
NSString *imgName=[@"imgname.png"];
[[NSUserDefaults standardUserDefaults]setValue:imgName forKey:@"imageName"];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:imgName];
UIImage *image = imageView.image; // imageView is my image from camera
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savedImagePath atomically:NO];
Retrive image:
NSString *imgName= [[NSUserDefaults standardUserDefaults]valueForKey:@"imageName"];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *filePath=[NSString stringWithFormat:@"%@/%@",documentsDir,imageName];
[imageview setImage:[UIImage imageWithContentsOfFile:filePath]];
#3
0
I am still not clear about what exactly you want. You can always Save Image in or Retrieve Image from Photo Library.
我还不清楚你究竟想要什么。您始终可以在图片库中保存图像或从图片库中检索图像。
#1
0
What you need to do is save the image data after selection inside the following delegate - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
You can get the image via the key UIImagePickerControllerOriginalImage
in the info dictionary and possibly assign it to an imageview or save it as mentioned by @Kalpesh. Check out apple's documentation for more info. Also check out this good tutorial that shows how to pick photos from the photo album or the camera.
您需要做的是在以下委托中选择后保存图像数据 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {您可以通过信息字典中的密钥UIImagePickerControllerOriginalImage获取图像,也可能将其分配给imageview或按@Kalpesh所述保存。查看Apple的文档以获取更多信息。另请参阅这个很好的教程,该教程介绍如何从相册或相机中挑选照片。
#2
3
Try this, Save image:
试试这个,保存图片:
NSString *imgName=[@"imgname.png"];
[[NSUserDefaults standardUserDefaults]setValue:imgName forKey:@"imageName"];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:imgName];
UIImage *image = imageView.image; // imageView is my image from camera
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savedImagePath atomically:NO];
Retrive image:
NSString *imgName= [[NSUserDefaults standardUserDefaults]valueForKey:@"imageName"];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *filePath=[NSString stringWithFormat:@"%@/%@",documentsDir,imageName];
[imageview setImage:[UIImage imageWithContentsOfFile:filePath]];
#3
0
I am still not clear about what exactly you want. You can always Save Image in or Retrieve Image from Photo Library.
我还不清楚你究竟想要什么。您始终可以在图片库中保存图像或从图片库中检索图像。