如何保存和检索相册中的照片及其名称

发布于 2024-11-17 16:01:55 字数 158 浏览 6 评论 0原文

我有以下疑问:

  1. 我们可以将照片(图像)保存到具有“特定名称”的相册中吗?或者我们可以在保存照片后访问照片的名称吗?

  2. 我们可以从相册中访问带有其名称的照片吗?

请帮忙。

提前致谢。

I have the following doubts:

  1. Can we save a photo(image) to photo album with a "specific name" or can we access the name of the photo after saving it?

  2. Can we access a photo with its name from the photo album?

Please help.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

友谊不毕业 2024-11-24 16:01:55

这是用用户指定名称写入图像的代码

 // 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...

 // Create file manager
 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]);

This is the code for writing images with user specified name

 // 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...

 // Create file manager
 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]);
寒江雪… 2024-11-24 16:01:55

使用委托UIImagePickerControllerDelegate来调用相机或图像库。

调用相机:

UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;

picker.sourceType = UIImagePickerControllerSourceTypeCamera;
isCamera = YES;

[self presentModalViewController:picker animated:YES];

调用库:

UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;

[picker setAllowsEditing:YES];

[self presentModalViewController:(UIViewController*)picker animated:YES];

完成后,将调用委托方法:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

将图像写入库使用:

UIImageWriteToSavedPhotosAlbum(currentImage, nil, nil, nil);

或将从照片库中选取的所选图像保存到 UIImage 并对其执行进一步的操作。

Using delegate UIImagePickerControllerDelegate for invoking camera or image library.

To Invoke Camera:

UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;

picker.sourceType = UIImagePickerControllerSourceTypeCamera;
isCamera = YES;

[self presentModalViewController:picker animated:YES];

To Invoke Library:

UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;

[picker setAllowsEditing:YES];

[self presentModalViewController:(UIViewController*)picker animated:YES];

Once done, delegate method gets called:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

To write image to library use:

UIImageWriteToSavedPhotosAlbum(currentImage, nil, nil, nil);

or save selected image picked from photo library to UIImage and perform further actions on it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文